我的图书馆项目使用...
package.json文件具有这些依赖项
"dependencies": {
"@types/d3": "^4.4.0" /* also tried moving this to devDeps */
},
"devDependencies": {
"cssnano": "^3.10.0",
"postcss-cssnext": "^2.9.0",
"postcss-nested": "^1.0.0",
"postcss-simple-vars": "^3.0.0",
"rollup": "^0.40.1",
"rollup-plugin-commonjs": "^7.0.0",
"rollup-plugin-livereload": "^0.4.0",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-postcss": "^0.2.0",
"rollup-plugin-serve": "^0.1.0",
"rollup-plugin-typescript": "^0.8.1",
"rollup-plugin-uglify": "^1.0.1",
"rollup-watch": "^3.1.0"
}
我的rollup.config.js文件已配置这些插件......
plugins: [
typescript(),
postcss({
extension: ['.css'],
plugins: [
simplevars(),
nested(),
cssnext({ warnForDuplicates: false }),
cssnano(),
],
}),
nodeResolve({
jsnext: true, //use jsnext if the node package supports it
main: true, //look for main file
browser: true, //if there is a browser version, use it
}),
commonjs(),
//uglify(),
serve({
contentBase: 'build',
port: '80',
}),
livereload(),
]
Rollup构建得很好。但是,在编辑器中,VSCode在d3符号上显示错误。当我将鼠标悬停在它上面时,我看到了这个错误...
[ts]' d3'是指UMD全局,但当前文件是一个模块。请考虑添加导入。
我可以添加此导入以使错误在编辑器中消失。
import d3 from '@types/d3';
然而,汇总失败并且......
无法解决' @ types / d3'来自' ...'
有没有办法配置vscode不显示错误,所以它不会淹没真正的错误?
是否有另一种方法可以在汇总项目中配置D3类型定义?
答案 0 :(得分:2)
您只定义了d3的TypeScript类型。您仍然需要将d3指定为依赖项。
的package.json
"dependencies": {
"@types/d3": "4.8.0",
"d3": "4.8.0"
}
您现在可以导入d3:
import * as d3 from "d3";