All posts
typescriptmodules

Fixing "Cannot find module 'typescript'"

Why this error happens when running tsc or type-aware tools, and how to fix TypeScript installation and resolution issues.

SR

Suhail Roushan

August 6, 2026

·
5 min read
·
0 views

Cannot find module 'typescript' is refreshingly literal: something in your toolchain (an editor, a build tool, a CLI command) is trying to load the TypeScript compiler package itself and can't find it installed — distinct from most module resolution errors involving your own application code, this one is specifically about the TypeScript tooling dependency being missing or misconfigured.

This error means the specific process trying to use TypeScript — your editor's language server, a tsc invocation, a bundler's TypeScript plugin, or a test runner's TypeScript transform — can't locate an installed typescript package in the location it expects, whether that's your project's node_modules, a global install, or a specific version pinned elsewhere.

Why This Error Happens

Different tools look for the typescript package in different ways: your editor typically expects a local (project-level) install to use the exact version and configuration your project specifies; CLI usage of tsc needs either a local install (run via npx tsc or a package script) or a global install; and build tools/bundlers with TypeScript integration expect it as a resolvable dependency from their own execution context. This error means whichever specific mechanism is being used didn't find a match.

Reproducing the Error

Running tsc without TypeScript installed as a project dependency:

tsc --version
# -bash: tsc: command not found
# or, if a global tsc exists but doesn't match project expectations:
npx tsc --version
# npm error could not determine executable to run
# (if typescript isn't installed at all, locally or globally)

An editor's TypeScript language server failing similarly:

Cannot find module 'typescript'.
The editor's TypeScript version could not be loaded.
Falling back to the bundled TypeScript version.

Core Concepts Behind This Error

Editors like VS Code bundle their own TypeScript version but prefer using your project's local installation for accuracy against your project's actual configuration and version — if your project doesn't have TypeScript installed locally, the editor either falls back to its bundled version (potentially causing version-mismatch confusion) or reports this error, depending on your editor's specific configuration.

Global vs. local TypeScript installs behave differently across contexts — a global tsc command works fine for quick ad-hoc compilation but doesn't respect project-specific version pinning, and CI environments almost always need a local install since they typically don't have (or shouldn't rely on) a global TypeScript installation.

A node_modules deletion or incomplete install (interrupted npm install, .gitignore'd node_modules not yet restored after cloning) is one of the most common practical causes — the fix is often simply running your package manager's install command, not a deeper configuration issue.

Monorepo/workspace setups can have TypeScript installed at the workspace root but not properly hoisted or linked to a specific package, causing this error for tools running from within that specific package's directory even though TypeScript is technically present somewhere in the broader repository.

Fixing "Cannot Find Module 'typescript'"

Fix 1: Install TypeScript as a local dev dependency, the standard, most broadly correct fix:

pnpm add -D typescript
# or: npm install --save-dev typescript

Fix 2: Configure your editor to use the project's local TypeScript version explicitly rather than its bundled version, ensuring consistency between what you see in the editor and what actually runs in builds/CI:

// VS Code: .vscode/settings.json
{ "typescript.tsdk": "node_modules/typescript/lib" }

Fix 3: For CI/build environments, ensure the install step runs before any TypeScript-dependent command, and verify it's not accidentally excluded via a production-only install flag:

# CI config
- run: pnpm install  # ensure devDependencies (including typescript) are installed
- run: pnpm tsc --noEmit

Fix 4: For monorepos, verify TypeScript is properly resolvable from the specific package's directory, either via workspace hoisting or an explicit local dependency in that package:

pnpm add -D typescript --filter your-package-name

Should TypeScript Be a Dependency or a devDependency?

Always a devDependency for application code — TypeScript is a build-time tool, not something your runtime code needs available in production. The one exception is a package specifically publishing .ts source for consumers to compile themselves (rare), which would need to consider TypeScript's role in its own dependency graph more carefully — but for the overwhelming majority of projects, devDependency is correct.

Preventing This Error in Production

Keep TypeScript pinned as an explicit local devDependency rather than relying on a global install anywhere in your toolchain — editor, local development, and CI should all resolve to the same project-local version. Configure your editor to use the workspace TypeScript version explicitly, avoiding a silent mismatch between what your editor reports and what your actual build process enforces.

If you hit this error, run your package manager's install command first — it resolves the large majority of cases, and if the error persists after that, check specifically whether the tool reporting the error is looking in the right place (local vs. global, or the right package in a monorepo).

Related posts

Written by Suhail Roushan — Full-stack developer. More posts on AI, Next.js, and building products at suhailroushan.com/blog.

Get in touch