【问题标题】:Angular Typescript - exclude is not working in tsconfig.jsonAngular Typescript - exclude 在 tsconfig.json 中不起作用
【发布时间】:2018-11-08 08:48:30
【问题描述】:

目前我在编译 Angular 4 项目时遇到 node_modules 中的一个模块的问题,并且出现如下错误,因此我决定在 tsconfig.json 中排除这个项目,但我仍然收到错误,可以有人在这里帮助我

ERROR in D:/workspace/demo/node_modules/@types/d3-collection/index.d.ts (148,23): ',' expected.

ERROR in D:/workspace/demo/node_modules/@types/d3-collection/index.d.ts (483,40): ',' expected.

ERROR in D:/workspace/demo/node_modules/@types/d3-collection/index.d.ts (148,25): Type parameter name cannot be 'any'

因此我决定排除 node_modules 以避免这些错误,但在运行 npm start 时我仍然面临同样的错误

tsconfig.json

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es6",
      "dom"
    ],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  },
  "exclude": [
    "**/node_modules/*"
  ]
}

【问题讨论】:

  • 试试这个"exclude": ["node_modules" ]
  • @JohnVelasquez 尝试了同样的错误

标签: angular typescript npm tsconfig


【解决方案1】:

您应该添加 skipLibCheck 它会跳过所有声明文件 (*.d.ts) 的类型检查。

https://www.typescriptlang.org/docs/handbook/compiler-options.html

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es6",
      "dom"
    ],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "skipLibCheck": true,
    "types": ["d3-collection"]
  },
  "exclude": [
    "node_modules"
  ]
}

【讨论】:

  • 这有助于减少 1 个错误,但其他 2 个错误仍然存​​在ERROR in D:/workspace/demo/node_modules/@types/d3-collection/index.d.ts (148,23): ',' expected. ERROR in D:/workspace/demo/node_modules/@types/d3-collection/index.d.ts (483,40): ',' expected.
  • 试试这个"module": "es2015"
  • 尝试重新安装类型npm install @types/d3-collection --save-dev
猜你喜欢
  • 2018-01-21
  • 1970-01-01
  • 1970-01-01
  • 2017-10-30
  • 2018-03-23
  • 2022-08-10
  • 2018-03-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多