Recently, I was working on a React project that required adding TypeScript to enhance type safety. After installing TypeScript and configuring the project, I encountered an annoying error: “Cannot find module TypeScript.”
This error can be frustrating when you’re trying to compile your TypeScript code or use TypeScript-related tools. Despite having TypeScript installed (or so I thought), my project couldn’t locate it.
In this article, I’ll walk you through the common causes of this error and provide proven solutions based on my 6+ years of TypeScript experience. So let’s dive in!
Understanding the “Cannot Find Module TypeScript” Error
This error typically occurs in Node.js environments when:
- TypeScript isn’t installed in your project.
- TypeScript is installed, but it is not referenced correctly.
- Path configurations in your project are incorrect.
- You’re using incompatible TypeScript versions.
The error message can appear in different contexts:
Error: Cannot find module 'TypeScript'Or sometimes with more details:
Error: Cannot find module 'TypeScript'
Require stack:
- /usr/local/lib/node_modules/ts-node/dist/index.jsMethod 1: Install TypeScript Locally
The most common solution is simply installing TypeScript locally in your project:
npm install typescript --save-devI’ve found this works in most cases because it ensures TypeScript is available specifically for your project. After installation, you can verify that it worked by checking your package.json file; you should see TypeScript listed under “devDependencies”.

Check Out: Difference Between Namespaces and Modules in TypeScript
Method 2: Install TypeScript Globally
If you work with TypeScript across multiple projects, a global installation might be more convenient:
npm install -g typescript
After installing globally, verify the installation with:
tsc --versionThis should display the TypeScript version if installed correctly. I recommend this approach for developers who frequently work with TypeScript across different projects.

Check Out: Define TypeScript Static Methods
Method 3: Check Your package.json and node_modules
Sometimes the error occurs despite TypeScript being listed in your package.json. In this case:
- Check if the node_modules folder contains TypeScript:
node_modules/typescript- If it’s missing, try deleting your node_modules folder and package-lock.json, then reinstall:
Remove-Item -Recurse -Force node_modules
rm package-lock.json
npm installI’ve encountered this issue multiple times when switching branches or merging code, and this solution usually resolves it.

Check Out: Require vs Import in TypeScript
Method 4: Fix Import/Require Statements
If you’re trying to import TypeScript directly into your code, you might be using incorrect syntax:
// Incorrect
import typescript from 'typescript';
// Correct
import * as ts from 'typescript';Or if using CommonJS:
// Correct
const ts = require('typescript');This ensures you’re importing TypeScript properly in your code. I’ve found that using the correct import syntax prevents many module resolution issues.
Method 5: Update Your tsconfig.json
Sometimes the issue is related to your TypeScript configuration. Check your tsconfig.json for proper module resolution settings:
{
"compilerOptions": {
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
"*": ["node_modules/*"]
}
}
}This configuration enables TypeScript to locate modules correctly. I’ve found that setting the correct moduleResolution option is particularly important when working with Node.js projects.

Method 6: Fix PATH Environment Variables
If you’ve installed TypeScript globally but still get the error, your system PATH might not include the npm global packages location:
For Windows:
- Find your npm global path with: npm config get prefix
- Add <npm-path>\node_modules\.bin to your PATH environment variable
For Mac/Linux:
export PATH=~/.npm-global/bin:$PATHThis ensures your system can find globally installed npm packages. I’ve noticed this issue often arises on new development machines or after system updates.
Method 7: Use npx to Run TypeScript Commands
If you can’t install TypeScript globally or want to use a specific version, npx is a great solution:
npx typescript --version
# or
npx tsc --versionThis runs the command using the project’s local TypeScript installation. I use this approach frequently in CI/CD pipelines where I don’t want to install packages globally.
Fixing “Cannot Find Module ‘TypeScript'” in Specific Environments
In VS Code
If you’re seeing this error in VS Code:
- Make sure the TypeScript extension is installed
- Check if VS Code is using the correct TypeScript version:
- Press Ctrl+Shift+P (or Cmd+Shift+P on Mac)
- Type “TypeScript: Select TypeScript Version”
- Choose “Use Workspace Version.”
In Angular Projects
Angular projects have specific TypeScript requirements:
npm install typescript@~4.8.0 --save-devReplace the version number with the one compatible with your Angular version. I’ve found that using incompatible TypeScript versions is a common source of issues in Angular projects.
In React Projects
For React projects using Create React App:
npm install --save-dev typescript @types/node @types/react @types/react-dom @types/jestThen, create a tsconfig.json file if it doesn’t already exist.
What Causes the Error?
Based on my experience, here are the most common causes of this error:
- Incomplete installation: npm install process was interrupted
- Version conflicts: Different parts of your project require different TypeScript versions
- Cache issues: npm or Node.js caching outdated information
- Path problems: The System can’t find where TypeScript is installed
- Project misconfiguration: Incorrect tsconfig.json or package.json settings
Understanding the root cause helps apply the right solution. When I encounter this error, I systematically work through these possible causes until I find the issue.
Preventing This Error in Future Projects
To avoid this error in future projects:
- Always include TypeScript in your package.json (preferably as a dev dependency)
- Use a .npmrc file to ensure consistent installations
- Document the TypeScript version requirements for your project
- Use package managers like Yarn or npm@7+ with better dependency resolution
- Consider using TypeScript project references for large codebases
These practices have helped my teams avoid TypeScript module resolution issues across multiple projects.
Conclusion
I hope you found this article helpful. If you’re working with TypeScript in your projects, implementing these solutions should resolve the “Cannot find module ‘typescript'” error.
Keep in mind that the specific solution depends on your project setup and development environment.
You may like to read:
- Difference Between Let vs Const in TypeScript
- Difference Between Record vs Object in TypeScript
- TypeScript vs React

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.