【问题标题】:Typescript error -- Error: Cannot find module 'typescript/tsc.js'打字稿错误-错误:找不到模块'typescript/tsc.js'
【发布时间】:2021-07-04 17:09:00
【问题描述】:

我不知道如何让我的“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

系统:Ubuntu 16.04 LTS

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

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

以上都没有给我任何结果。 非常感谢您的帮助。

【问题讨论】:

    标签: node.js typescript module tsc


    【解决方案1】:

    对于那些对此感到困惑的人,应该使用 local tsc 运行的命令是:

    npx tsc

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2018-01-03
        • 1970-01-01
        • 1970-01-01
        • 2019-12-21
        • 2014-11-21
        • 1970-01-01
        • 1970-01-01
        • 2017-11-05
        • 2021-10-17
        相关资源
        最近更新 更多