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

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

我不知道如何让我的 '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' 目录中。

节点--版本:12.18.4

npm --version: 6.14.6

系统:Ubuntu16.04 LTS

我已经尝试了针对类似问题提出的许多解决方案,但都没有成功:

上面的

None 得到了任何结果。 非常感谢您的帮助。

对于那些受困于此的人,运行 与 local tsc 的命令应该是:

npx tsc

要使 tsc --version 命令正常工作,请尝试使用 npm install -g typescript 命令进行安装。它在全球范围内安装打字稿。