Skip to content
Latchkey

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.

Node output
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.

Terminal
npm install -D typescript
# build with dev deps (do not strip them before tsc runs)
npm ci
npx tsc --version

Keep build tooling for the build step

  1. Do not run --omit=dev before the TypeScript build.
  2. Ensure typescript satisfies the peer range of ts-node/tsx/eslint.
  3. Prune to production only after the build is done.

How to prevent it

  • Declare typescript in devDependencies, not globally.
  • Build before pruning dev deps.
  • Match the typescript version to tool peer ranges.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →