Cannot find module 'typescript'

Viewed 4212

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 typescript@3.9.4 

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
1 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.

Related