简体   繁体   中英

Typescript error -- Error: Cannot find module 'typescript/tsc.js'

I cannot figure out how to make my 'tsc' command working:

tsc
module.js:472
    throw err;
    ^

Error: Cannot find module 'typescript/tsc.js'
    at Function.Module._resolveFilename (module.js:470:15)

My 'package.json' has:

"devDependencies": {
    "@types/node": "^14.11.2",
    "tslib": "^2.0.1",
    "typedoc": "^0.19.2",
    "typescript": "^4.0.3"
  }

And my 'tsconfig.json':

{
  "compilerOptions": {
    "target": "es6",
    "sourceMap": true,
    "declaration": true,
    "declarationDir": "dist/types",
    "strict": true,
    "noUnusedLocals": true,
    "lib": [
      "es2019"
    ]
  },
  "include": [
    "src"
  ]
}

No error during 'npm install'.

When I check up the 'node_modules' folder, typescript exists and the 'tsc.js' file exists within the 'typescript/lib' directory.

node --version: 12.18.4

npm --version: 6.14.6

system: Ubuntu 16.04 LTS

I have tried many of the solution proposed for a similar issue without success:

  • delete the node_modules folder and then run npm install again
  • try to reinstall manually: npm install typescript --save-dev
  • using: npm install typescript-tools --save-dev
  • ...

None of the above gets me any result. Thank you very much for your help.

对于那些遇到问题的人,应该使用本地 tsc运行的命令是:

npx tsc

To make the tsc --version command working, try to install using npm install -g typescript command. It installs the typescript globally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM