我正在尝试使用webpack4捆绑基于d3的客户端应用程序。但是,当捆绑代码时,会产生以下错误:
/* Cannot get final name for export "default" in "./node_modules/d3-selection/index.js"
(known exports: , known reexports: create creator local matcher mouse namespace namespaces
clientPoint select selectAll selection selector selectorAll style touch touches
window event customEvent) */
undefined.select('body')
.append('canvas')
.attr('id', 'mycanvas')
.attr('width', 640)
.attr('height', 480);
在我的来源中我有
import selection from 'd3-selection';
selection.select('body')
.append('canvas')
.attr('id', 'mycanvas')
.attr('width', 640)
.attr('height', 480);
我不确定这是否是一个相关症状但是当我尝试import selection as d3sel from 'd3-selection';
时,我从webpack收到一条关于无法声明该声明的错误。
我的package.json文件如下:
"devDependencies": {
"d3-selection": "^1.3.0",
"webpack": "^4.10.2",
"webpack-cli": "^3.0.2"
}
答案 0 :(得分:1)
也许选择不是默认导出?
尝试
import { selection } from 'd3-selection';