Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect module import #36

Open
esauter5 opened this issue May 20, 2016 · 0 comments
Open

Incorrect module import #36

esauter5 opened this issue May 20, 2016 · 0 comments
Labels

Comments

@esauter5
Copy link

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.

@addyosmani addyosmani added the bug label May 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants