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

Using transform on node_module #53

Closed
ichabodcole opened this issue Feb 27, 2015 · 3 comments
Closed

Using transform on node_module #53

ichabodcole opened this issue Feb 27, 2015 · 3 comments

Comments

@ichabodcole
Copy link

I'm requiring some node modules that are written in es6. I have been searching for a way to do this since browserify does not run transforms on modules from the node_modules folder by design.
The options I have seen are to add a browserify attribute the to modules package.json, which seems like a bad idea since it is not a module I have created. The other option I found was to use transform({global: true}, babelify), but I get a compile error if I do this "ReferenceError: Unknown option: global while parsing file: /Users/...". Would greatly appreciate any guidance in figuring out how to do this.

@ecurtis
Copy link

ecurtis commented Feb 27, 2015

I am having the same issue.

@sebmck
Copy link

sebmck commented Feb 28, 2015

This is built-in browserify behaviour and can not be overridden, an alternative is to add:

{
  "browserify": {
    "transform": ["babelify"]
  }
}

to your node_modules package.json.

In the future please search the issues before creating a new one, thanks! See #44 and #38.

@Jimbly
Copy link

Jimbly commented Oct 5, 2018

I was having this issue as well, and since Google results for "browserify babel node_modules" comes to this issue, and lots of other issues link here, I'm updating it with details on the other solution (using a global transform), which seems to work better than trying to ask every single modern module I require to add something to their package.json.

After figuring this out through other means, I see it's actually in the FAQ for babelify, so I'm quoting that section here:

Another solution (proceed with caution!) is to run babelify as a global transform. Use the babel ignore option to narrow the number of files transformed:

browserify().transform("babelify", {
  global: true,
  ignore: /\/node_modules\/(?!app\/)/
});

The above example will result in a transform that also includes the app module in node_modules: the global flag transform all files, and the ignore regular expression then excludes all those in the node_modules directory except those that are in node_modules/app (since ?! will match if the given suffix is absent).

In my use, I find the ignore is not required, as for every module that exports ES5 code, babelify is effectively a no-op, and for those that are not, I want it to run them though babelify. Seems safer to opt-out of babelify if it breaks a particular module (which will be noticed in development) rather than need to opt-in (which will only be noticed in production/testing on old browsers).

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

4 participants