简体   繁体   English

打字稿错误 -- 错误:找不到模块“打字稿/tsc.js”

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

I cannot figure out how to make my 'tsc' command working:我不知道如何让我的 'tsc' 命令工作:

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:我的“package.json”有:

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

And my 'tsconfig.json':还有我的“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'. “npm install”期间没有错误。

When I check up the 'node_modules' folder, typescript exists and the 'tsc.js' file exists within the 'typescript/lib' directory.当我检查“node_modules”文件夹时,打字稿存在并且“tsc.js”文件存在于“typescript/lib”目录中。

node --version: 12.18.4节点 --version: 12.18.4

npm --version: 6.14.6 npm --version: 6.14.6

system: Ubuntu 16.04 LTS系统: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删除 node_modules 文件夹,然后再次运行 npm install
  • try to reinstall manually: npm install typescript --save-dev尝试手动重新安装: npm install typescript --save-dev
  • using: npm install typescript-tools --save-dev使用: 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.要使tsc --version命令工作,请尝试使用npm install -g typescript命令进行npm install -g typescript It installs the typescript globally.它全局安装打字稿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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