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

Add browserify in package.json for ES6 #1653

Closed
binarykitchen opened this issue May 29, 2019 · 6 comments · Fixed by dudleycarr/nsqjs#314
Closed

Add browserify in package.json for ES6 #1653

binarykitchen opened this issue May 29, 2019 · 6 comments · Fixed by dudleycarr/nsqjs#314

Comments

@binarykitchen
Copy link
Contributor

Now that with v3.x my app is breaking since it's browserify + babelify configuration doesn't transform node_modules by default.

See https://github.com/babel/babelify#faq for background.

Suggestion is to add this in your package.json

{
  "browserify": {
    "transform": [["babelify", { "presets": ["@babel/preset-env"] }]]
  }
}

This will ensure that any app using async and building it with browserify + babelify gets transpiled correctly.

Thanks!

@aearly
Copy link
Collaborator

aearly commented May 30, 2019

It seems a bit odd to have to configure browserify here for your project. Shouldn't this type of config go in your project's bundler config?

@binarykitchen
Copy link
Contributor Author

I hear you. Although some other modules do that so it's not unusual. And ultimately we all have to transpile to ES5. This is one solution to flag that package is ES6 and needs transpilation.

Don't want to tell browserify to babelify all node modules which would slow down build enormously.

@aearly aearly closed this as completed in f4dc8e4 Jun 23, 2019
@gabegorelick
Copy link

gabegorelick commented Jul 9, 2019

I'm glad this fixed someone's workflow, but it broke mine 😄.

We run browserify but target Node.js (browserify is useful to generate single JS files). This change means we now get a Cannot find module 'babelify' from '/node_modules/async' error. We can work around that by adding ignoreTransform: ['babelify'] though.

In general, I think this change means that anyone running browserify over async will need to either add babelify as a dependency or take steps to ignore the transform.

@alanshaw
Copy link

alanshaw commented Jul 22, 2019

Broke ours too. If you need to babelify a particular node module can't it be configured in your project? Not everyone transpiles to ES5.

cc @aearly

@aearly
Copy link
Collaborator

aearly commented Aug 1, 2019

I'm considering removing the browserify-specific config. I didn't like doing it in the first place.

@nappy
Copy link

nappy commented Feb 21, 2020

What are you thinking? Why do I need to add "babelify" "@babel/core" and "@babel/preset-env" to my project. I do not want to use babel. I just want to bundle my dependencies.

Even if I would use a transpiler, this whole concept does not work with devDependencies. Why should every library provide its own rollup/webpack/browserify config and then require downstream to include their dev dependencies manually?

Also now that I am doing that, I am not able to change the configuration. For example how am I supposed to manage polyfills (regenerator-runtime in this case), if I cannot even change the @babel/preset-env configuration (for example to "usage"), or the target?

This is madness. I will just stick with v2. Thanks. Babelify my ass. (humour)

A more resonable approach would be to target a specific node version, and if you want to use newer features in your source, then transpile it yourself prior to publishing to npm, or just leave them in and leave it to downstream how they want to transpile it for their environment as necessary.

This approach (sorry if I repeat mysdelf) is complete nonsense.

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

Successfully merging a pull request may close this issue.

5 participants