4

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
2
  • So, this is the package you are trying to run? npm:ts. Commented Sep 21, 2020 at 20:43
  • I run compile with command npx ts Commented Sep 22, 2020 at 8:38

4 Answers 4

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

npm link typescript and delete node_module didn't help. thank for your help. In another computer perfect ......
@zloctb I've read somewhere that it has to be done in this particular order, for some reason: npm install -g typescript npm link typescript
1

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

Comments

0

What worked for me was to follow the advised steps in exact sequence:

  1. Delete node_module folder
  2. Delete package-lock.json
  3. npm install
  4. npm install typescript
  5. npm link typescript
  6. npm start
  7. For any further missing dependencies do npm install [dep] followed by npm link [dep]

Comments

0

Update your node version, node -v v12.16.1 is too old.

You can do it with https://github.com/nvm-sh/nvm

nvm use 18

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.