TypeScript错误--错误:找不到模块'typescript/tsc.js'。

3

我无法弄清如何使我的“tsc”命令工作:

tsc
module.js:472
    throw err;
    ^

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

我的 'package.json' 文件包含:

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

我的 'tsconfig.json':

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

'npm install'过程中没有任何错误。

当我检查'node_modules'文件夹时,发现 TypeScript 已经存在,并且 'tsc.js' 文件存在于 'typescript/lib' 目录下。

node 版本:12.18.4

npm 版本:6.14.6

系统环境:Ubuntu 16.04 LTS

我尝试了很多类似问题的解决方案,但都没有成功:

  • 删除 node_modules 文件夹,再次运行 npm install
  • 尝试手动重新安装:npm install typescript --save-dev
  • 使用:npm install typescript-tools --save-dev
  • ...

以上方法都无法解决问题。 非常感谢您的帮助。

2个回答

1

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

npx tsc


1
为了让 tsc --version 命令正常工作,请尝试使用 npm install -g typescript 命令进行安装。它会全局安装 TypeScript。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接