-
Notifications
You must be signed in to change notification settings - Fork 178
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
ES6 code in npm #21
Comments
Hello, You can still use version 1.x.x of fetch-mock in node 0.12, but I recommend upgrading to node 4.2 (which is deemed stable and supported) to use fetchMock 2. There are some nice new shorthand features available as of v2.2.2, so there are benefits to using the latest code. In node 0.12 It may be possible to create a wrapper module something like
And then require this in your tests. Let me know how you get on |
I’m already using Babel in my project but by default Babel ignores anything in Right now I’m using fetch-mock 1.x. I think I’ll just update Node to 4.x when I have more time at work. |
@wheresrhys would upgrading to node 4.2 solve this issue when running in a Karma/Babel/PhantomJS test running scenario? |
Is this PhantomJs 2? Phantomjs 1.9.x has really out of date support for a lot of browser APIs so I wouldn't expect it to work there, but I haven't tried in Phantom2. I'll add Phantom2 and firefox to CI to see if it unearths any specific problems. |
PhantomJS 2 dies because it doesn't understand ES6 syntax (the exact error is related to not understanding |
weird, babel should take care of that. Does your karma.conf contain a line like this https://github.com/wheresrhys/fetch-mock/blob/master/karma.conf.js#L15 and do you have babelify installed as a dev dependency? On a different project I had a very similar problem a few days ago (unrelated to fetch-mock and running in karma-firefox), which suggests it was a babelify/karma-browserify bug. It seemed to have fixed itself spontaneously yesterday, so maybe try (if you haven't already) |
Yep, just added phantom and firefox to ci and all runs fine, so I reckon it's some glitchy version of something in the karma-babel-browserify setup you're running |
I'm in the same situation as @sapegin, where I'm using Babel but by default Babel ignores anything in |
I'll consider adding a babelified build to future npm releases, but have
|
That would make Babel muuuch slower. |
I think this comes out of a general desire not to export library code in ES6. I think there are some tools to help with the translation, so that anyone with any setup can plop it into their node_modules without having to track down a SyntaxError. Maybe something like this? http://www.hammerlab.org/2015/07/09/bundling-and-distributing-complex-es6-libraries-in-an-es5-world/ |
For Node (not browser) it’s just Babel, like this. |
v2 of fetch-mock does explicitly drop support for non es6 environments https://github.com/wheresrhys/fetch-mock/releases/tag/v2.0.0, so I'm not too concerned about node<4 (but will document better). Probably gonna have to include a pre-babelified version for the browser though, which is a pain. npm & babel should solve this problem |
Fixed with the PR above. |
npm package (2.1.0) contains not transpiled ES6 code which cases an error for me:
The text was updated successfully, but these errors were encountered: