How to fix Cannot resolve typescript module for ts-node in TypeScript

TypeScriptINTERMEDIATEMEDIUMUpdated Dec 11, 2025ยท 118 views

This error occurs when ts-node cannot find or load the TypeScript module. The issue is typically caused by missing TypeScript installation, incorrect module resolution, or version conflicts between ts-node and TypeScript.

Quick fix

Fixes Cannot resolve typescript module for ts-node

# Check package.json
cat package.json | grep typescript

# Or check node_modules
ls node_modules | grep typescript

# Or use npm
npm list typescript
  1. Check if TypeScript is installed locally
  2. Install TypeScript as a dev dependency
  3. Check ts-node and TypeScript version compatibility
  4. Clear npm cache and reinstall dependencies
typescript โ€” error
# Check package.json
cat package.json | grep typescript
# Or check node_modules
ls node_modules | grep typescript
# Or use npm
npm list typescript
Cannot resolve typescript module for ts-node

What this error means

When you run a TypeScript file with ts-node, it needs to load the TypeScript compiler module to transpile your code. The error "Cannot resolve typescript module for ts-node" means ts-node cannot locate or load the TypeScript module from your project's dependencies. This can happen for several reasons: 1. TypeScript is not installed in your project (missing from package.json) 2. TypeScript is installed globally but ts-node expects a local installation 3. There's a version mismatch between ts-node and TypeScript 4. Module resolution is failing due to incorrect Node.js module resolution settings 5. The TypeScript module is corrupted or not properly installed ts-node uses Node.js's module resolution algorithm to find TypeScript. If it can't find TypeScript where it expects, this error appears.

Typical symptoms

  • Error appears when running ts-node with a TypeScript file
  • Command fails immediately with 'Cannot resolve typescript module for ts-node'
  • Works with npx ts-node but not with direct ts-node command
  • TypeScript files fail to execute even though TypeScript is installed
  • Error occurs in CI/CD pipelines or Docker containers
  • Works on one machine but fails on another with same code

Common causes

  1. TypeScript is not installed in your project (most common)
  2. TypeScript is installed globally but ts-node expects local installation
  3. Version mismatch between ts-node and TypeScript packages
  4. Using an incompatible TypeScript version (too old or too new)
  5. Node.js module resolution issues (incorrect NODE_PATH or module resolution settings)
  6. Corrupted node_modules or package-lock.json file
  7. Running ts-node from a different directory than project root
  8. Monorepo setup where TypeScript is in root but ts-node runs in sub-package

How to fix "Cannot resolve typescript module for ts-node"

1Check if TypeScript is installed locally

First, verify TypeScript is installed in your project:

bash
# Check package.json
cat package.json | grep typescript

# Or check node_modules
ls node_modules | grep typescript

# Or use npm
npm list typescript

If TypeScript is not listed, you need to install it.

2Install TypeScript as a dev dependency

Install TypeScript in your project:

bash
# Install the latest stable version
npm install --save-dev typescript

# Or install a specific version compatible with your ts-node
npm install --save-dev typescript@4.9.5

# If using yarn
yarn add --dev typescript

# If using pnpm
pnpm add --save-dev typescript

After installation, verify it's in your package.json and node_modules.

3Check ts-node and TypeScript version compatibility

Ensure your ts-node and TypeScript versions are compatible:

bash
# Check installed versions
npx ts-node --version
npx tsc --version

# Or check package.json
cat package.json | grep -A2 -B2 'ts-node|typescript'

Common compatibility issues:
- ts-node v10+ requires TypeScript v4.7+
- Older ts-node versions may not work with TypeScript v5+

Update if needed:

bash
# Update both to latest compatible versions
npm install --save-dev ts-node@latest typescript@latest
4Clear npm cache and reinstall dependencies

If TypeScript appears installed but still not found, clear cache and reinstall:

bash
# Clear npm cache
npm cache clean --force

# Remove node_modules and package-lock.json
rm -rf node_modules package-lock.json

# Reinstall all dependencies
npm install

# Alternative: Use npm ci for clean install
npm ci

This fixes corrupted installations and ensures clean module resolution.

5Use npx or local ts-node binary

Ensure you're using the local ts-node installation:

bash
# Use npx (recommended)
npx ts-node your-file.ts

# Or explicitly use local binary
./node_modules/.bin/ts-node your-file.ts

# Add to package.json scripts
{
  "scripts": {
    "start": "ts-node src/index.ts"
  }
}

Avoid global ts-node installations which may have different module resolution paths.

6Configure ts-node module resolution

If issues persist, configure ts-node's module resolution:

json
// tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true
  }
}

Or use ts-node with explicit TypeScript path:

bash
# Specify TypeScript compiler
npx ts-node --compiler typescript your-file.ts

# Or use ts-node programmatically
require('ts-node').register({
  compiler: 'typescript',
  transpileOnly: true
});

Advanced notes

### Global vs Local Installations

ts-node prefers local TypeScript installations. If you have TypeScript installed globally, ts-node may still fail because:
1. Global modules have different resolution paths
2. Permission issues with global npm installations
3. Version conflicts between global and local

Uninstall global TypeScript if not needed:

bash
npm uninstall -g typescript

### Monorepo Considerations

In monorepos (Turborepo, Nx, Lerna), TypeScript might be installed at root level. Solutions:

1. Install TypeScript in each package (recommended):

bash
# In each package directory
npm install --save-dev typescript

2. Use workspace protocol (if supported):

json
{
  "devDependencies": {
    "typescript": "workspace:*"
  }
}

3. Configure module resolution in tsconfig.json:

json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "typescript": ["../node_modules/typescript"]
    }
  }
}

### Docker and CI/CD Environments

In containerized environments:
1. Ensure TypeScript is in dependencies (not just devDependencies if needed at runtime)
2. Copy package.json and run npm install before running ts-node
3. Set NODE_PATH if using custom module resolution:

dockerfile
ENV NODE_PATH=/app/node_modules

### Alternative: Use tsx or esbuild-runner

If ts-node issues persist, consider alternatives:
- tsx: Faster TypeScript execution
- esbuild-runner: Very fast, minimal configuration
- swc: Rust-based, extremely fast

bash
# Install and use tsx
npm install --save-dev tsx
npx tsx your-file.ts

Frequently asked questions

What does "Cannot resolve typescript module for ts-node" mean?
When you run a TypeScript file with ts-node, it needs to load the TypeScript compiler module to transpile your code. The error "Cannot resolve typescript module for ts-node" means ts-node cannot locate or load the TypeScript module from your project's dependencies. This can happen for several reasons: 1.
How do I fix "Cannot resolve typescript module for ts-node"?
This error occurs when ts-node cannot find or load the TypeScript module. The issue is typically caused by missing TypeScript installation, incorrect module resolution, or version conflicts between ts-node and TypeScript.
What causes "Cannot resolve typescript module for ts-node"?
TypeScript is not installed in your project (most common) TypeScript is installed globally but ts-node expects local installation Version mismatch between ts-node and TypeScript packages
Is the "Cannot resolve typescript module for ts-node" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading