Last modified: Jun 26, 2025 By Alexander Williams

Fix Error: Cannot find module 'typescript'

If you see the error Cannot find module 'typescript', your Node.js project is missing the TypeScript dependency. This guide will help you fix it.

Why does this error occur?

The error happens when Node.js cannot locate the TypeScript package. This usually means TypeScript is not installed in your project.

Common causes include:

  • TypeScript was not installed
  • Wrong installation location
  • Corrupted node_modules
  • Path issues

Solution 1: Install TypeScript locally

The simplest fix is to install TypeScript in your project. Run this command in your project root:


npm install typescript --save-dev

This adds TypeScript as a dev dependency. Check your package.json to confirm the installation.

Solution 2: Install TypeScript globally

For CLI usage, install TypeScript globally:


npm install -g typescript

Verify with tsc -v. This helps if you get similar errors like Cannot find module 'webpack'.

Solution 3: Reinstall dependencies

If TypeScript is in package.json but still missing, try:


rm -rf node_modules package-lock.json
npm install

This cleans and reinstalls all dependencies. It also fixes issues like Cannot find module 'eslint'.

Solution 4: Check your import statement

Ensure your import matches your installation type. For global installs use:


require('typescript/register');

For local installs use:


const ts = require('typescript');

Solution 5: Verify your PATH

For global installs, check your PATH includes npm's global directory. Run:


npm bin -g

Add this path to your system PATH if missing. This also applies to errors like Cannot find module 'nodemon'.

Solution 6: Use npx for one-time commands

If you only need TypeScript temporarily, use npx:


npx tsc --version

This runs TypeScript without permanent installation.

Preventing future issues

To avoid this error:

  • Always document dependencies in package.json
  • Use consistent installation methods
  • Consider using Docker for environment consistency

Conclusion

The Cannot find module 'typescript' error has simple solutions. Most often, installing TypeScript locally or globally fixes it. Always check your installation method matches your usage.

For similar module errors, check our guides on Cannot find module 'react' and other common issues.