我试图导入D3,以便在Angular2模块中使用它。
一些背景信息:
我所做的:
结果是,TSC给了我错误消息“无法找到模块'd3'”。我错过了什么或者做错了什么?
发布于 2016-06-20 15:16:16
因此,如果在package.json中,您已经有了一个类似的依赖项:
"dependencies": {
...
"d3": "^3.5.17",
...
}然后您可以进入/tools/config/seed.config.ts并在SYSTEM_CONFIG_DEV对象中添加'd3':‘${this.NPM_BASE}3/d3.min.js’,如下所示:
protected SYSTEM_CONFIG_DEV: any = {
defaultJSExtensions: true,
packageConfigPaths: [
`${this.NPM_BASE}*/package.json`,
`${this.NPM_BASE}**/package.json`,
`${this.NPM_BASE}@angular/*/package.json`
],
paths: {
[this.BOOTSTRAP_MODULE]: `${this.APP_BASE}${this.BOOTSTRAP_MODULE}`,
'@angular/core': `${this.NPM_BASE}@angular/core/bundles/core.umd.js`,
'@angular/common': `${this.NPM_BASE}@angular/common/bundles/common.umd.js`,
'@angular/compiler': `${this.NPM_BASE}@angular/compiler/bundles/compiler.umd.js`,
'@angular/forms': `${this.NPM_BASE}@angular/forms/bundles/forms.umd.js`,
'@angular/http': `${this.NPM_BASE}@angular/http/bundles/http.umd.js`,
'@angular/router': `${this.NPM_BASE}@angular/router/index.js`,
'@angular/platform-browser': `${this.NPM_BASE}@angular/platform-browser/bundles/platform-browser.umd.js`,
'@angular/platform-browser-dynamic': `${this.NPM_BASE}@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js`,
'rxjs/*': `${this.NPM_BASE}rxjs/*`,
'd3': '${this.NPM_BASE}d3/d3.min.js',
'app/*': `/app/*`,
'*': `${this.NPM_BASE}*`
},
packages: {
rxjs: { defaultExtension: false }
}如果有帮助请告诉我。谢谢!
发布于 2016-12-19 22:28:22
我也有同样的问题,上面的答案帮助调试了我的解决方案--因为它确定了它是一个配置问题,但是使用angular2 2@2.1.0,我必须更新{root}/e2e/tscconfig.json (添加:
"types": [
"d3"
]如下所示:
{
"compileOnSave": false,
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"outDir": "../dist/out-tsc-e2e",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types"
],
"types": [
"d3"
]
}
}请记住,{root}/src/中也有一个tscconfig.json。我在这方面进行了更新,但仍然存在依赖问题:
import * as D3 from 'd3';在我的组件中,通过错误。希望这至少能帮到一个人!
发布于 2018-10-03 09:39:23
角5+
你可以这样做:
npm i -g typings
npm i d3@3.5.5 --save
typings install d3=github:DefinitelyTyped/DefinitelyTyped/d3/d3.d.ts#6e2f2280ef16ef277049d0ce8583af167d586c59 --global --savehttps://stackoverflow.com/questions/37925477
复制相似问题