Systemjs: Import of d3 does not equal global d3 object

Created on 9 Sep 2015  路  3Comments  路  Source: systemjs/systemjs

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?

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.

All 3 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brianjenkins94 picture brianjenkins94  路  7Comments

guybedford picture guybedford  路  7Comments

ArmorDarks picture ArmorDarks  路  7Comments

Nedlinin picture Nedlinin  路  7Comments

JeroenVinke picture JeroenVinke  路  3Comments