-
Notifications
You must be signed in to change notification settings - Fork 166
Open
Labels
Description
I believe the module docs are incorrect. Based on this lib/math.js
export function sum(x, y) {
return x + y;
}
export var pi = 3.141593;
The docs say we can import like this
import math from 'lib/math';
console.log('2π = ' + math.sum(math.pi, math.pi));
But I think this is incorrect. In this case math is undefined
because there is no default export. The correct import would be:
import * as math from 'lib/math';
or if you wanted to just destructure:
import { pi, sum } from Math;
I made this mistake today when dealing with code that was mixed with requires and import. These two statements below look equivalent because they similar structure which I think leads to the confusion:
var math = require('lib/math');
import math from 'lib/math';
There's a great reference here: http://www.2ality.com/2014/09/es6-modules-final.html for anyone who happens to come across this issue.