简体   繁体   English

webpack 4和d3 es6导入不起作用

[英]webpack 4 and d3 es6 imports not working

I'm trying to use webpack4 to bundle a d3 based client application. 我正在尝试使用webpack4捆绑基于d3的客户端应用程序。 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'; 我不确定这是否是相关症状,但是当我尝试import selection as d3sel from 'd3-selection'; i get an error from webpack about not being able to pase the statement. 我从webpack收到一个错误消息,关于无法执行该语句。

My package.json file looks like: 我的package.json文件如下所示:

"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';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM