Borislav Hadzhiev
Sun Feb 20 2022·1 min read
Photo by Jamie Street
To solve the cannot find module 'typescript' error, make sure to install
typescript
globally by running the npm i -g typescript
command and create a
symbolic link from the globally-installed package to node_modules
by running
the npm link typescript
command.
Open your terminal in your project's root directory and run the following commands:
# ✅ Install TypeScript globally npm install -g typescript # ✅ Create a symbolic link from the global package # to node_modules/ of current folder npm link typescript
Once you run the two commands, the error should be resolved.
If the global installation of TypeScript fails, you might have to run the
command with sudo
.
You can check if you have TypeScript installed successfully, by running the following command:
tsc --version
The output of the command should show the version of the TypeScript package on
your machine, e.g. 4.8.0
.
The npm link command creates
a symbolic link from the globally installed package to the node_modules/
directory of the current folder.
If the error is not resolved, try to delete your node_modules
and
package-lock.json
files, re-run npm install
and restart your IDE.
rm -rf node_modules package-lock.json npm install npm link typescript
Make sure to restart your IDE if the error still persists. VSCode glitches often and a reboot solves things sometimes.
If this also doesn't work, try installing TypeScript locally.
npm install --save-dev typescript
This will add typescript to the development dependencies of your project, so you
don't have to run the link
command.