I'm trying to use webpack4 to bundle a d3 based client application. However when the code is bundled it produces the following error:
/* 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);
In my source I have
import selection from 'd3-selection';
selection.select('body')
.append('canvas')
.attr('id', 'mycanvas')
.attr('width', 640)
.attr('height', 480);
I'm not sure if this is a related symptom or not but when I try import selection as d3sel from 'd3-selection';
i get an error from webpack about not being able to pase the statement.
My package.json file looks like:
"devDependencies": {
"d3-selection": "^1.3.0",
"webpack": "^4.10.2",
"webpack-cli": "^3.0.2"
}
Perhaps selection isn't the default export?
Try
import { selection } from 'd3-selection';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.