Error exporting a const d3.map

时间:2018-04-20 00:34:09

标签: javascript webpack ecmascript-6

I try to export a d3.map dictionary using webpack:

import {map, select} from 'd3';

const positionSelect = position => {
  select(position).node().getBoundingClientRect();
};


const dictionary = map();
dictionary.set('Pitcher', positionSelect('#pitcher'))
  .set('Catcher', positionSelect('#catcher'))
  .set('First Base', positionSelect('#firstbase'))
  .set('Second Base', positionSelect('#secondbase'))
  .set('Shortstop', positionSelect('#shortstop'))
  .set('Third Base', positionSelect('#thirdbase'))
  .set('Left Field', positionSelect('#leftfield'))
  .set('Center Field', positionSelect('#centerfield'))
  .set('Right Field', positionSelect('#rightfield'));

export dictionary;

I get this error:

Module build failed: SyntaxError: Unexpected token, expected { (19:7)

17 |   .set('Right Field', positionSelect('#rightfield'));
18 | 
19 | export dictionary;
   |        ^
20 | 

Is there a syntax problem?

1 个答案:

答案 0 :(得分:1)

export声明的syntax不正确;你可以从字面上阅读错误信息。如果要导出先前使用命名导出声明的常量,则必须将其括在大括号中:

export { dictionary };

但是,您可以在声明常量时执行导出。在这种情况下,不得使用大括号:

export const dictionary = map();