【问题标题】:Npm server with Typescript error TS18003带有 Typescript 错误 TS18003 的 Npm 服务器
【发布时间】:2017-12-28 14:09:51
【问题描述】:

使用 typescript 为 Angular 2 设置环境。 npm lite 运行成功,但安装 typescript 并添加启动脚本后,出现错误

错误 TS18003:在配置文件“D:/practical/ang1/tsconfig.json”中找不到输入。指定的 'include' 路径是 '["**/"]' 和 'exclude' 路径是 '["../wwwroot/app","node_modules/"]'。

package.json

  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\"",
    "test": "echo \"Error: no test specified\" && exit 1",
    "lite": "lite-server",
    "tsc": "tsc",
    "tsc:w": "tsc -w"
  },

tsconfig.json

{
  "compilerOptions": {
    "lib": [ "es5", "dom" ],
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  }
}

如何解决这个错误

注意 第一次“npm start”工作正常,但删除和重置后,导致上述问题

【问题讨论】:

    标签: angular typescript npm-start


    【解决方案1】:

    在做了一些挖掘之后,我在compilerOptions下的tsconfig.json中添加了这一行。

    "typeRoots" : ["../node_modules/@types/"]
    

    【讨论】:

    • 配置转译通常是一个漫长而艰巨的过程,需要进行许多更改才能获得最终解决方案。一般来说,一个人的单行更改不会经常有帮助。
    【解决方案2】:

    faisaljanjua 为这个难题提供了一个有用的部分。

    "typeRoots" : ["../node_modules/@types/"]
    

    但我也需要

        "types": [
          "node"
        ],
    
    

    (请注意,将节点添加到类型也会泄漏 npm 包,因此请务必排除它们。) 和

          "baseUrl": "./*",
          "paths": {
              "@/*":["./*"]
          },
    

    ./ 是您的 tsconfig 文件所在的当前文件夹。

    自从我将节点添加到类型。我需要在此处添加 node_modules,因为它们归 npm 所有,这是一个底层的节点工具。

      "exclude": [
        ".git",
        "bin",
        "build",
        "node_modules"
      ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 2017-10-14
      • 1970-01-01
      • 2012-12-22
      • 2020-01-06
      相关资源
      最近更新 更多