We just got caught by the following.
Consider the most simple of jspm projects (setup according to these instructions). Then:
jspm install d3
along with the following ES6 code:
import * as d3 from "d3";
console.log(d3 === window.d3); // this outputs false
_the fact that this code is written in ES6 is I think irrelevant, because my test transpiles to ES5_
This is very significant because D3 uses the global window.d3 to set d3.event and the like.
I realise the import is effectively redundant here, but if present shouldn't the result of console.log be true?
@myitcv import * returns an ES6 module namespace object. This is a special module object, which will never be equivalent to any ES5 object.
Rather use import d3 from 'd3' if you're looking for this equivalence when loading ES5 modules.
@guybedford thanks, I was certain there was a simple explanation to what we were doing wrong :+1:
For whatever reason now (maybe because I'm using SystemJS and JSPM), this only worked using:
import 'd3/d3';
for me.
Most helpful comment
@myitcv
import *returns an ES6 module namespace object. This is a special module object, which will never be equivalent to any ES5 object.Rather use
import d3 from 'd3'if you're looking for this equivalence when loading ES5 modules.