This error occurs when TypeScript cannot resolve a language service plugin specified in your tsconfig.json. Language service plugins enhance TypeScript's editor integration with features like SQL/GraphQL validation, CSS linting in template strings, or ESLint integration. The resolution failure typically happens due to incorrect plugin paths, missing dependencies, or module resolution conflicts.
The "Plugin resolution failed for X" error indicates that TypeScript's language service cannot locate or load a plugin specified in your tsconfig.json file. Language service plugins are editor extensions that provide additional functionality like enhanced error messages, auto-completion, or specialized linting for specific domains (SQL, GraphQL, CSS-in-JS, etc.). When TypeScript encounters this error, it means the plugin module cannot be resolved through Node.js's module resolution algorithm. This could be because: 1. The plugin package is not installed in your node_modules 2. The plugin path is incorrect or uses an unsupported module format 3. There are module resolution conflicts between CommonJS and ESM 4. The plugin has missing dependencies or incompatible TypeScript version This error prevents the plugin from loading, which means you won't get the enhanced editor features the plugin provides, though your TypeScript compilation may still work.
First, check if the plugin package is actually installed in your node_modules directory:
# Check if plugin is installed
npm list typescript-plugin-name
# or
yarn why typescript-plugin-name
# or
pnpm list typescript-plugin-name
# If not installed, install it:
npm install --save-dev typescript-plugin-name
# or
yarn add --dev typescript-plugin-name
# or
pnpm add --save-dev typescript-plugin-nameMake sure the plugin name in your package.json matches exactly what you have in tsconfig.json.
Verify your tsconfig.json has the correct plugin configuration. The plugin should be specified in the "compilerOptions.plugins" array:
{
"compilerOptions": {
"plugins": [
{
"name": "typescript-plugin-name"
}
]
}
}Some plugins require additional configuration options. Check the plugin's documentation for the exact format. Also ensure you're not mixing plugin names with file paths incorrectly.
Check your moduleResolution setting in tsconfig.json. Some plugins may require specific module resolution strategies:
{
"compilerOptions": {
"moduleResolution": "node",
"plugins": [
{
"name": "typescript-plugin-name"
}
]
}
}If your plugin is an ESM module but your project uses CommonJS (or vice versa), you may need to adjust your tsconfig.json. Try setting "moduleResolution" to "node16" or "nodenext" for ESM plugins.
Ensure your TypeScript version is compatible with the plugin. Some plugins only work with specific TypeScript versions:
# Check your TypeScript version
npx tsc --version
# Check plugin compatibility requirements
# (usually in plugin's README or package.json)If there's a version mismatch, you may need to:
1. Update TypeScript: npm install --save-dev typescript@latest
2. Downgrade TypeScript to a compatible version
3. Find an alternative plugin that supports your TypeScript version
Use TypeScript's traceResolution flag to debug module resolution issues:
{
"compilerOptions": {
"traceResolution": true,
"plugins": [
{
"name": "typescript-plugin-name"
}
]
}
}Then run TypeScript with verbose output:
npx tsc --extendedDiagnosticsThis will show you exactly how TypeScript is trying to resolve the plugin module, which can reveal path issues or resolution conflicts.
If relative paths are causing issues, try using absolute paths or module aliases:
{
"compilerOptions": {
"plugins": [
{
"name": "/absolute/path/to/node_modules/typescript-plugin-name/lib/index.js"
}
],
"paths": {
"typescript-plugin-name": ["./node_modules/typescript-plugin-name/lib/index.js"]
}
}
}Alternatively, if the plugin is published as a package, ensure you're using the package name (not a file path) and that Node.js can resolve it through normal module resolution.
Language service plugins in TypeScript are different from compiler plugins. They run inside the editor (like VS Code) to provide enhanced editing experience, not during the compilation process. This means:
1. Editor-specific: Plugins may work in some editors (VS Code) but not others
2. Version sensitivity: Plugins often depend on specific TypeScript language service API versions
3. Performance impact: Complex plugins can slow down editor responsiveness
4. Alternative approaches: For build-time transformations, consider using:
- Babel plugins with @babel/preset-typescript
- SWC plugins
- esbuild plugins
- Custom TypeScript transformers via ttypescript or ts-patch
If you consistently have plugin resolution issues, consider whether you truly need a language service plugin or if the functionality could be achieved through other tools like ESLint plugins, Prettier, or custom VS Code extensions.
Function expression requires a return type
Function expression requires a return type
Value of type 'string | undefined' is not iterable
How to fix "Value is not iterable" in TypeScript
Type 'undefined' is not assignable to type 'string'
How to fix "Type undefined is not assignable to type string" in TypeScript
Type narrowing from typeof check produces 'never'
How to fix "Type narrowing produces never" in TypeScript
Type parameter 'T' has conflicting constraints
How to fix "Type parameter has conflicting constraints" in TypeScript