繁体   English   中英

Angular 2找不到@types模块

[英]@types module not found with Angular 2

我花了比我更愿意承认的时间,所以我举起手来。

我有一个模块要包含在我的angular 2项目中:

import * as d3ScaleChromatic from 'd3-scale-chromatic';

这给出了一个错误:

Cannot find module 'd3-scale-chromatic'.

我已经通过npm npm install --save @types/d3-scale-chromatic 我可以说它存在于node_modules/@types/d3-scale-chromatic

我的tsconfig.json看起来像这样:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"   <-- should look here, right?
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

因此,我可以看到它将在node_modules / @ types中查找。

似乎类似于此问题,但据我所知,我已经遵循了线程中的建议: https : //github.com/Microsoft/TypeScript/issues/9725

谁能告诉我在模块中正确引用此软件包所缺少的内容吗?

编辑:仔细检查后,我的应用程序中实际上有4个tsconfig。*文件。 我怀疑这是问题的根源。 现在的问题是,我需要保留其中哪些?

tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": ["@types/d3-scale-chromatic"]
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

tsconfig.spec.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "baseUrl": "./",
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "test.ts"
  ],
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ]
}

tsconfig.e2e.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/e2e",
    "baseUrl": "./",
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jasmine",
      "jasminewd2",
      "node"
    ]
  }
}

您还需要安装:

npm install --save d3-scale-chromatic

随着:

npm install --save @types/d3-scale-chromatic

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM