Volar TypeScript Language Service
This package, `volar-service-typescript`, integrates TypeScript language services into Volar, a powerful language tooling framework primarily developed for Vue and other web technologies. Currently at version 0.0.70, it functions as a critical plugin within the Volar ecosystem, providing essential features such as accurate type checking, intelligent code completion, robust refactoring capabilities, and comprehensive error diagnostics specifically tailored for TypeScript files within projects utilizing Volar. As an official component of the broader Volar project, its release cadence is closely tied to Volar's own development cycle, which typically involves continuous integration with frequent updates and patch releases, often aligning with the evolution of TypeScript itself. Its key differentiator is its role as the official and most deeply integrated method for leveraging TypeScript's full capabilities directly within Volar-powered development environments, ensuring seamless functionality and optimized performance compared to more generic language server integrations or alternative solutions.
Common errors
-
Cannot find module 'volar-service-typescript'
cause The package `volar-service-typescript` is not installed in your project.fixRun `npm install volar-service-typescript` or `yarn add volar-service-typescript` to install the package. -
TypeError: (0 , volar_service_typescript__WEBPACK_IMPORTED_MODULE_0__.create) is not a function
cause This error typically occurs in bundled environments (like Webpack) when attempting to default import a named CommonJS export, or incorrect destructuring.fixEnsure you are using named imports: `import { create } from 'volar-service-typescript';` for ESM, or correct destructuring for CJS: `const { create } = require('volar-service-typescript');`. -
The "@volar/language-service" peer dependency is not installed.
cause Volar's core language service, a peer dependency, is missing from your project.fixInstall the peer dependency: `npm install @volar/language-service@~2.4.0` (adjust version to match your Volar installation's requirement).
Warnings
- breaking Major version updates of `@volar/language-service` often introduce breaking changes that require updating `volar-service-typescript` to a compatible version. Always check the Volar release notes.
- gotcha TypeScript version mismatches between your project's `typescript` dependency and the version Volar or its services might be using can lead to unexpected type errors or incorrect diagnostics.
- gotcha Changes to the `volar.config.js` structure or the `create()` function's options between Volar versions can lead to service not loading or incorrect behavior.
Install
-
npm install volar-service-typescript -
yarn add volar-service-typescript -
pnpm add volar-service-typescript
Imports
- create
import create from 'volar-service-typescript';
import { create } from 'volar-service-typescript'; - create
const create = require('volar-service-typescript');const { create } = require('volar-service-typescript');
Quickstart
/* volar.config.js */
module.exports = {
// Other Volar configurations...
services: [
// Integrate the TypeScript language service
require('volar-service-typescript').create({
// Optional: Custom TypeScript plugin options
// E.g., disable default semantic diagnostics if handled externally
// diagnosticSemantic: false,
}),
],
};
/* Example tsconfig.json (in your project root) */
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
// ... other TS options
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}