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

Generated Code contains require -> no warnings #6807

Open
yanosz opened this Issue Nov 12, 2017 · 9 comments

Comments

Projects
None yet
6 participants
@yanosz

yanosz commented Nov 12, 2017

Current situation:

Transpiling

import hello from './helloworld' 

Generates:

var _hello = require("./hello");
var _hello2 = _interopRequireDefault(_hello);

Without any warning.

Problem

This is confusing, since the homepage says that:
"Put in next-gen JavaScript - Get browser-compatible JavaScript out" - however, hardly any browser supports require(.) out of the box.

Propsals

  1. (Preferred): Do not generate 'require (.)' by default. Implement namespaces for modules on a global module, only. Show a note, that all .js files have to be loaded by the HTML.
  2. (Alternative): Keep require. Output a warning, that additional libraries such as require.js are needed. Provide a hint (HTML-Source-Code) how to include these.
  3. (last resort): Output a warning, that the result is not "browser-compatible JavaScript", due to "require".
@babel-bot

This comment has been minimized.

Show comment
Hide comment
@babel-bot

babel-bot Nov 12, 2017

Collaborator

Hey @yanosz! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

Collaborator

babel-bot commented Nov 12, 2017

Hey @yanosz! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@hzoo

This comment has been minimized.

Show comment
Hide comment
@hzoo

hzoo Nov 13, 2017

Member

We assume if you are using babel in the browser you are using a bundler like rollup/webpack, it's always been this way. Would be cool to add a warning but we would somehow have to know if you don't have a bundler, which I don't know how you would do atm. If you are building babel in the browser you need to use it with babel-loader, otherwise it's for node

Member

hzoo commented Nov 13, 2017

We assume if you are using babel in the browser you are using a bundler like rollup/webpack, it's always been this way. Would be cool to add a warning but we would somehow have to know if you don't have a bundler, which I don't know how you would do atm. If you are building babel in the browser you need to use it with babel-loader, otherwise it's for node

@yanosz

This comment has been minimized.

Show comment
Hide comment
@yanosz

yanosz Nov 15, 2017

IMHO this is basically a usability issue and not about whether something like webpack is reasonable or not.

If we go for 2) imho it's practical to output a warning while having a command line switch for disabling specific warnings.

By that the default is helpful for users calling babel-cli manually, while 3rd party devlopers can disable this warning if needed.

yanosz commented Nov 15, 2017

IMHO this is basically a usability issue and not about whether something like webpack is reasonable or not.

If we go for 2) imho it's practical to output a warning while having a command line switch for disabling specific warnings.

By that the default is helpful for users calling babel-cli manually, while 3rd party devlopers can disable this warning if needed.

@nicolo-ribaudo

This comment has been minimized.

Show comment
Hide comment
@nicolo-ribaudo

nicolo-ribaudo Nov 15, 2017

Member

If you don't specify a module format and thus Babel output require() calls, it will crash as soon as you open your code in a browsers.
I don't think a warning is needed, since the configuration problem will be noticed in the very early stages of development.

Member

nicolo-ribaudo commented Nov 15, 2017

If you don't specify a module format and thus Babel output require() calls, it will crash as soon as you open your code in a browsers.
I don't think a warning is needed, since the configuration problem will be noticed in the very early stages of development.

@yanosz

This comment has been minimized.

Show comment
Hide comment
@yanosz

yanosz Nov 15, 2017

Well, I strongly disagree. If babel produces code that crashes, a warning certainly reasonable.

Warnings are supposed to help users avoiding long bug hunts.

Getting back to: "Put in next-gen JavaScript - Get browser-compatible JavaScript out" users expect to get browser-compatible JavaScript out of babel - by that, they're looking at ways on how to configure babel.

yanosz commented Nov 15, 2017

Well, I strongly disagree. If babel produces code that crashes, a warning certainly reasonable.

Warnings are supposed to help users avoiding long bug hunts.

Getting back to: "Put in next-gen JavaScript - Get browser-compatible JavaScript out" users expect to get browser-compatible JavaScript out of babel - by that, they're looking at ways on how to configure babel.

@xtuc

This comment has been minimized.

Show comment
Hide comment
@xtuc

xtuc Nov 15, 2017

Member

I agree with your point. This is the first time I've heard a complain about it, I assume that most user know that bundling is required in that case.

We cannot really emit a warning a think because the bundling is usually a separate process.

Member

xtuc commented Nov 15, 2017

I agree with your point. This is the first time I've heard a complain about it, I assume that most user know that bundling is required in that case.

We cannot really emit a warning a think because the bundling is usually a separate process.

@yanosz

This comment has been minimized.

Show comment
Hide comment
@yanosz

yanosz Nov 15, 2017

Providing some detauls:

Is:

es2015-demo/babel$ ./node_modules/.bin/babel -d build/ src
src/app.js -> build/app.js                                                                                                                              
src/hello.js -> build/hello.js

More helpful:

es2015-demo/babel$ ./node_modules/.bin/babel -d build/ src
src/app.js -> build/app.js
WARNING: Transpiled output contains require(.) - consider postprocessing using packers <LINK>                                                                                                                    
src/hello.js -> build/hello.js

es2015-demo/babel$ ./node_modules/.bin/babel --disable-warnings:require -d build/ src
src/app.js -> build/app.js
src/hello.js -> build/hello.js

Technically this is possible, IMHO.

yanosz commented Nov 15, 2017

Providing some detauls:

Is:

es2015-demo/babel$ ./node_modules/.bin/babel -d build/ src
src/app.js -> build/app.js                                                                                                                              
src/hello.js -> build/hello.js

More helpful:

es2015-demo/babel$ ./node_modules/.bin/babel -d build/ src
src/app.js -> build/app.js
WARNING: Transpiled output contains require(.) - consider postprocessing using packers <LINK>                                                                                                                    
src/hello.js -> build/hello.js

es2015-demo/babel$ ./node_modules/.bin/babel --disable-warnings:require -d build/ src
src/app.js -> build/app.js
src/hello.js -> build/hello.js

Technically this is possible, IMHO.

@c-johnson

This comment has been minimized.

Show comment
Hide comment
@c-johnson

c-johnson Dec 9, 2017

Hi, I'm a basic dummy JS developer trying to "Babelify" my code (using gulp-babel) and am also confused by this issue. I thought that Babel would take my ES6 source code and convert it into usable Javascript, which it does not. So +1 for including this as a warning or changing the marketing for Babel to say "Put in next-gen JavaScript - Get bytecode for eventual browser-compatible JavaScript out with a bundler like Webpack or Rollup"

c-johnson commented Dec 9, 2017

Hi, I'm a basic dummy JS developer trying to "Babelify" my code (using gulp-babel) and am also confused by this issue. I thought that Babel would take my ES6 source code and convert it into usable Javascript, which it does not. So +1 for including this as a warning or changing the marketing for Babel to say "Put in next-gen JavaScript - Get bytecode for eventual browser-compatible JavaScript out with a bundler like Webpack or Rollup"

@nicolo-ribaudo

This comment has been minimized.

Show comment
Hide comment
@nicolo-ribaudo

nicolo-ribaudo Dec 9, 2017

Member

You can output amd modules instead of commonjs. Then you only need to add an amd loader (like RequireJS) to your HTML, without needing a bundler.

Member

nicolo-ribaudo commented Dec 9, 2017

You can output amd modules instead of commonjs. Then you only need to add an amd loader (like RequireJS) to your HTML, without needing a bundler.

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