Node "Cannot find module 'typescript'" - Fix Missing tsc in CI
TypeScript-driven tools - tsc, ts-node, tsx, type-aware linters - require the typescript package to be resolvable. In CI it goes missing when devDependencies are stripped, a peer is unmet, or it was only ever installed globally.
What this error means
A build or type-check step fails with Cannot find module 'typescript' (often from ts-node or a tool that loads tsc). It works locally where typescript is installed but fails in a CI job that does not install it.
Error: Cannot find module 'typescript'
Require stack:
- /app/node_modules/ts-node/dist/index.js
at Function._resolveFilename (node:internal/modules/cjs/loader)
... code: 'MODULE_NOT_FOUND'Common causes
typescript is a devDependency stripped in a prod install
A --omit=dev (or NODE_ENV=production) install drops typescript, so any tool needing it cannot resolve it.
typescript is an unmet peer of a tool
ts-node/tsx/type-aware ESLint declare typescript as a peer. If it is not in the project, the tool cannot load it.
How to fix it
Install typescript as a project dependency
Add typescript to devDependencies and run the build with dev deps present.
npm install -D typescript
# build with dev deps (do not strip them before tsc runs)
npm ci
npx tsc --versionKeep build tooling for the build step
- Do not run
--omit=devbefore the TypeScript build. - Ensure
typescriptsatisfies the peer range of ts-node/tsx/eslint. - Prune to production only after the build is done.
How to prevent it
- Declare
typescriptin devDependencies, not globally. - Build before pruning dev deps.
- Match the typescript version to tool peer ranges.