Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module 'typescript'

Yesterday works but today I have this error. I reinstall globally and local

npm i --save-dev typescript
npm i -g typescript

and lower version

npm install  -g [email protected] 

remove from directory AppData\Roaming\npm but this doesnt work. remove node_modules too

tsconfig

{
    "compilerOptions": {
        "target": "es5",
        "removeComments": true,
        "outFile": "app.js",
        "lib": ["es2017", "dom"]
    },
    "files":[
        "app.ts",
        "inter.ts",
    ]
}

I run command

npx ts

and then I had got error :

Cannot find module 'typescript'

$ npm -v
6.13.4
$ node -v
v12.16.1
like image 727
zloctb Avatar asked Oct 27 '25 15:10

zloctb


2 Answers

Sometimes you may need to link the package manually, as it may conflict if there's an existing node_modules already.

Try this:

npm link typescript

An alternative solution would be to delete the node_modules folder and then run npm install again.

like image 174
PatricNox Avatar answered Oct 29 '25 05:10

PatricNox


Add "typescript": "~4" to package.json's devDependencies works for me.

like image 33
Rundong-MSFT Avatar answered Oct 29 '25 04:10

Rundong-MSFT