TypeScript Auto-Import Cache
typescript-auto-import-cache is a utility package within the Volar.js ecosystem, currently at version 0.3.6, designed to address the performance bottleneck in the TypeScript Language Service Completion API, specifically when calculating auto-imports. It achieves this by porting and optimizing the `tsserver`'s internal auto-import caching logic. This package functions as a TypeScript Language Service Plugin, meaning it extends the functionality of the TypeScript language server (`tsserver`) to enhance the developer experience in IDEs (like VS Code) by speeding up IntelliSense for auto-imports. It is primarily a tooling-oriented package, not intended for direct runtime use in application code, and typically sees updates aligned with new TypeScript versions or Volar.js releases that may impact language service performance. Its key differentiator is its focused approach to optimizing a common pain point in large TypeScript projects, directly integrating with the underlying language service architecture.
Common errors
-
Plugin 'typescript-auto-import-cache' failed to load. Its 'create' function did not return a language service.
cause The plugin's factory function either threw an error during initialization or returned an invalid object that didn't conform to the Language Service Plugin interface, often due to an incompatible TypeScript version or internal plugin issue.fixEnsure your project's `typescript` dependency is compatible with the `typescript-auto-import-cache` plugin. Try updating `typescript-auto-import-cache` to the latest version. Check editor settings to confirm the workspace TypeScript version is being used. Refer to the plugin's GitHub issues for known compatibility problems. -
Error: Cannot find module 'typescript-auto-import-cache' from '.../tsserver'
cause The TypeScript language server (tsserver) could not locate the `typescript-auto-import-cache` package in `node_modules`. This typically happens if the package isn't installed or if `tsserver` is resolving modules from an unexpected location.fixRun `npm install typescript-auto-import-cache` or `yarn add typescript-auto-import-cache`. Ensure your editor is configured to use the workspace TypeScript version, which will instruct `tsserver` to look in your project's `node_modules` for plugins.
Warnings
- breaking As a `0.x.y` version package, `typescript-auto-import-cache` may introduce breaking changes without adhering to semantic versioning for major versions. Updates should be tested carefully.
- gotcha Language Service Plugins are sensitive to the TypeScript version used by your editor/IDE. Incompatibility between the plugin's expected TypeScript version and the project's or editor's TypeScript version can lead to the plugin failing to load or unexpected behavior.
- gotcha This package is a performance optimization for the TypeScript Language Service (tsserver), meaning its impact is primarily on IDE responsiveness for auto-imports, not on the `tsc` compilation speed or runtime performance of your application.
- gotcha Incorrect `tsconfig.json` paths or plugin configuration (e.g., typos in the plugin name) will cause the plugin to not load silently or with generic errors in the TypeScript server logs, leading to no performance benefits.
Install
-
npm install typescript-auto-import-cache -
yarn add typescript-auto-import-cache -
pnpm add typescript-auto-import-cache
Imports
- TypeScript Language Service Plugin
import { enableAutoImportCache } from 'typescript-auto-import-cache'; // Incorrect usage in application code. const plugin = require('typescript-auto-import-cache'); // Incorrect CommonJS require for direct use.This package is not imported directly into user application code. It's configured via `tsconfig.json` as a plugin.
Quickstart
{
"compilerOptions": {
"plugins": [
{
"name": "typescript-auto-import-cache"
}
],
"target": "es2020",
"module": "esnext",
"lib": ["es2020", "dom"],
"jsx": "react-jsx",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"allowJs": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}