我在这件事上花的时间比我愿意承认的要多,所以我举起手来。
我有一个模块,我正试图将其包含在我的Range2项目中:
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"
]
}
}发布于 2018-03-28 16:51:20
您还需要安装:
npm install --save d3-scale-chromatic连同:
npm install --save @types/d3-scale-chromatichttps://stackoverflow.com/questions/48634786
复制相似问题