Giter Site home page Giter Site logo

ES6 code in npm about fetch-mock HOT 14 CLOSED

wheresrhys avatar wheresrhys commented on June 23, 2024
ES6 code in npm

from fetch-mock.

Comments (14)

wheresrhys avatar wheresrhys commented on June 23, 2024

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

require('babel/register');
module.exports = require('fetch-mock');

And then require this in your tests. Let me know how you get on

from fetch-mock.

sapegin avatar sapegin commented on June 23, 2024

I’m already using Babel in my project but by default Babel ignores anything in node_modules.

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.

from fetch-mock.

carpeliam avatar carpeliam commented on June 23, 2024

@wheresrhys would upgrading to node 4.2 solve this issue when running in a Karma/Babel/PhantomJS test running scenario?

from fetch-mock.

wheresrhys avatar wheresrhys commented on June 23, 2024

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.

from fetch-mock.

carpeliam avatar carpeliam commented on June 23, 2024

PhantomJS 2 dies because it doesn't understand ES6 syntax (the exact error is related to not understanding const).

from fetch-mock.

wheresrhys avatar wheresrhys commented on June 23, 2024

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) rm -Rf node_modules and reinstall all your dependencies too. This is the project that was broken and fixed itself https://github.com/Financial-Times/next-feature-flags-client/tree/mvt

from fetch-mock.

wheresrhys avatar wheresrhys commented on June 23, 2024

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

from fetch-mock.

carpeliam avatar carpeliam commented on June 23, 2024

I'm in the same situation as @sapegin, where I'm using Babel but by default Babel ignores anything in node_modules.

from fetch-mock.

wheresrhys avatar wheresrhys commented on June 23, 2024

I'll consider adding a babelified build to future npm releases, but have
you tried passing {ignore:false} in to babel-core/register. Does that not
work?
On Sat, 7 Nov 2015 at 5:16 p.m., Liam Morley [email protected]
wrote:

I'm in the same situation as @sapegin https://github.com/sapegin, where
I'm using Babel but by default Babel ignores anything in node_modules.


Reply to this email directly or view it on GitHub
#21 (comment)
.

from fetch-mock.

sapegin avatar sapegin commented on June 23, 2024

That would make Babel muuuch slower.

from fetch-mock.

carpeliam avatar carpeliam commented on June 23, 2024

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/

from fetch-mock.

sapegin avatar sapegin commented on June 23, 2024

For Node (not browser) it’s just Babel, like this.

from fetch-mock.

wheresrhys avatar wheresrhys commented on June 23, 2024

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

from fetch-mock.

wheresrhys avatar wheresrhys commented on June 23, 2024

Fixed with the PR above.

from fetch-mock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.