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

Unable to Babel #2644

Closed
danilopolani opened this issue Jan 5, 2017 · 5 comments
Closed

Unable to Babel #2644

danilopolani opened this issue Jan 5, 2017 · 5 comments

Comments

@danilopolani
Copy link

I can't transform underscore.min with Babel. I need it because, with gulp, I merge all files and then process them with babel, but with underscore it returns an error.

You can try it out here: https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015

At the bottom of the right panel an error appears: "u is undefined".

@captbaritone
Copy link
Collaborator

captbaritone commented Jan 5, 2017

I'm getting "Cannot read property '_' of undefined", which is different but also broken.

Which version of Underscore are you using?

I'm suspicious that this is related to #2153 which has been fixed in master, but we have not yet shipped a release that includes it.

You could try it with the version of Underscore on master (https://github.com/jashkenas/underscore/blob/master/underscore.js) and see if that resolves the issue?

Let me know what you find.

@danilopolani
Copy link
Author

I'm using the version 1.8.3, the latest. Unfortunately, I cannot use the unminified version, because of the "require" methods not supported.

exports is not supported in the browser, you need a commonjs environment such as node.js/io.js, browserify/webpack etc

@captbaritone
Copy link
Collaborator

Where are you seeing the error with exports? I see that message when using the Babel website to transpile it, but the code looks fine. While Underscore references the exports variable, it first detects which environment it's in a only uses exports if it finds itself running in a node environment.

Basically, that "error" might just be Babel trying too hard to be helpful.

@rally25rs
Copy link

rally25rs commented Feb 27, 2017

Edited after more research

I just noticed... The actual last line of Underscore is to invoke itself with this:

}.call(this));

However after built by Babel, the last line is changed to pass undefined:

}.call(undefined));

It seems that in ES6 modules, this is supposed to be undefined (though I'm having a hard time processing the actual ECMA specification to determine if that is true) so Babel replaces it automatically.

StackOverflow: How to stop babel from transpiling 'this' to 'undefined'

Screenshot from Babel's online interpreter:

screen shot 2017-02-26 at 9 56 47 pm

@Kosta-Github
Copy link

Kosta-Github commented Apr 20, 2017

I think, this is fixed with this commit: 8a847ba from @lexdene

however, there is no official release available containing this fix; the current version 1.8.3 does not contain it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants