# VS Code TypeScript Errors
The TypeScript language server keeps crashing, or you see type errors that shouldn't exist. IntelliSense shows wrong types, or import statements don't resolve despite correct paths. TypeScript development in VS Code relies on the TypeScript server (tsserver), and when it malfunctions, debugging becomes guesswork.
Understanding TypeScript Server
VS Code's TypeScript support runs a separate process (tsserver) that:
- Analyzes your TypeScript/JavaScript files
- Provides IntelliSense suggestions
- Shows type errors and diagnostics
- Handles go-to-definition and references
When tsserver crashes or misbehaves, you lose all TypeScript features.
Step 1: Restart the TypeScript Server
Most TypeScript issues resolve with a simple restart:
- 1.Command palette:
- 2.
Ctrl+Shift+P - 3."TypeScript: Restart TS Server"
Or reload window:
Ctrl+Shift+P → "Developer: Reload Window"
This fixes transient crashes and stale state issues.
Step 2: Check TypeScript Server Log
See what's actually failing:
Enable verbose logging:
``json
{
"typescript.tsserver.log": "verbose",
"typescript.tsserver.trace": "verbose"
}
- 1.View logs:
- 2.Output panel → "TypeScript" dropdown
- 3.Look for crash reports and error messages
Common errors:
``
[error] The TypeScript server died unexpectedly 5 times
[error] Cannot find module 'typescript'
[error] Project '...' could not be configured correctly
Step 3: Fix tsconfig.json Configuration
A broken tsconfig.json causes endless problems:
Create proper tsconfig.json:
``json
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
Generate default tsconfig:
``bash
npx tsc --init
Check for monorepo issues:
If you have multiple tsconfig.json files, ensure references are correct:
``json
// In root tsconfig.json for monorepo
{
"references": [
{ "path": "./packages/core" },
{ "path": "./packages/app" }
]
}
Step 4: Fix Missing Type Definitions
Type errors often stem from missing type packages:
Install common types:
``bash
npm install --save-dev @types/node @types/react @types/express
Check package has types: ```bash # Package with built-in types npm info package-name types
# Or check DefinitelyTyped npm info @types/package-name ```
Handle untyped packages:
Create declarations for packages without types:
``typescript
// declarations.d.ts
declare module 'untyped-package' {
export function init(config: any): void;
export default function main(): void;
}
Step 5: Increase TypeScript Server Memory
Large projects cause tsserver to crash from memory exhaustion:
{
"typescript.tsserver.maxTsServerMemory": 8192
}Default is 3GB. For massive projects, increase to 8GB or more.
Monitor memory: Watch the TypeScript output for "exceeded memory budget" messages.
Step 6: Use Workspace TypeScript Version
VS Code bundles TypeScript, but your project might need a different version:
- 1.Select TypeScript version:
- 2.Open a TypeScript file
- 3.Status bar shows TypeScript version
- 4.Click the version number
- 5."Use Workspace Version"
Or configure explicitly:
``json
{
"typescript.tsdk": "node_modules/typescript/lib"
}
Install TypeScript in project:
``bash
npm install --save-dev typescript
Step 7: Fix Import Resolution Issues
Imports not resolving despite correct paths indicate configuration issues:
Check moduleResolution:
``json
{
"compilerOptions": {
"moduleResolution": "node" // or "bundler" for Vite/Webpack
}
}
Check baseUrl and paths:
``json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@components/*": ["./src/components/*"]
}
}
}
Verify path exists:
``bash
# Check if path mapping is correct
ls src/components/
Step 8: Handle JavaScript Files in TypeScript Project
Mixed JS/TS projects need special handling:
Enable JS checking:
``json
{
"compilerOptions": {
"allowJs": true,
"checkJs": true
}
}
Use jsconfig for JS-only projects:
If your project is JavaScript but uses TypeScript features:
``json
// jsconfig.json
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"checkJs": true,
"baseUrl": "."
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
Step 9: Clear Caches and Rebuild
Stale caches cause persistent issues:
Delete TypeScript caches:
``bash
rm -rf node_modules/.cache
rm -rf .tsbuildinfo
rm -rf tsconfig.tsbuildinfo
Reinstall TypeScript:
``bash
rm -rf node_modules/typescript
npm install typescript
Clear VS Code caches:
Ctrl+Shift+P → "Developer: Clear Cache"
Step 10: Fix Duplicate TypeScript Extensions
Multiple TypeScript extensions can conflict:
Check for duplicates:
``bash
code --list-extensions | grep typescript
Expected:
- ms-vscode.vscode-typescript-next (optional, for nightly TS)
Problematic duplicates: - Any extension providing TypeScript language services
Disable all but the built-in TypeScript extension.
Verification
Test TypeScript works correctly:
- 1.Open a .ts file
- 2.Type
const x: string =- IntelliSense should suggest string methods - 3.Import a local module - should resolve without error
- 4.Check "Problems" panel for type errors
- 5.Go to definition (F12) should work on any symbol
Quick Reference
| Problem | Likely Cause | Solution |
|---|---|---|
| TS server crashes | Memory or config | Increase memory, check tsconfig |
| Types not found | Missing @types | Install type definitions |
| Imports not resolved | Wrong paths config | Check baseUrl and paths |
| Wrong TS version | Bundle mismatch | Use workspace version |
| JS not checked | allowJs missing | Enable in tsconfig |
| Stale errors | Cache issue | Clear caches, restart |
TypeScript issues almost always stem from tsconfig.json configuration or missing type definitions. Start with restarting the server, then verify configuration.