Skip to content

Fix babel preset useESModules option #6249

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

Closed
wants to merge 2 commits into from
Closed

Conversation

dallonf
Copy link
Contributor

@dallonf dallonf commented Jan 22, 2019

Currently, useESModules only affects @babel/plugin-transform-runtime (so the compiled code does not reference ESM versions of @babel/runtime). This is somewhat misleading, since the resulting code will still contain ES Module syntax if the source uses it.

With this update, useESModule: false really means that the resulting code will not contain ES Module syntax.

I tested this locally in my company's fork of create-react-app.

Currently, `useESModules` only affects `@babel/plugin-transform-runtime` (so the compiled code not reference ESM versions of `@babel/runtime`). This is somewhat misleading, since the resulting code will still contain ES Module syntax if the source uses it. 

With this update, `useESModule: false` really means that the resulting code will not contain ES Module syntax.
@strayiker
Copy link

Duplicates #5973

@stale
Copy link

stale bot commented Mar 1, 2019

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Mar 1, 2019
@dallonf
Copy link
Contributor Author

dallonf commented Mar 5, 2019

Not sure why the build is failing, it doesn't really seem related to the changes I made:

Error: [BABEL] /tmp/tmp.JCPJgDVomq/test-kitchensink/src/index.js: Cannot find module '@babel/plugin-transform-react-jsx' (While processing: "/tmp/tmp.JCPJgDVomq/test-kitchensink/node_modules/babel-preset-react-app/index.js$1")
    at Array.reduce (<anonymous>)

@stale
Copy link

stale bot commented Apr 23, 2019

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Apr 23, 2019
@dallonf
Copy link
Contributor Author

dallonf commented Apr 23, 2019

I'd still like to see if this could be reviewed

@ianschmitz
Copy link
Contributor

Can you elaborate more on this change? What does it improve or fix?

@dallonf
Copy link
Contributor Author

dallonf commented Apr 27, 2019

If you use babel-preset-react-app outside of react-scripts, like if you're building a component library with it, by default the @babel/plugin-transform-runtime will add references to ESM files in @babel/runtime, which contain import statements. If you want to ship a CommonJS-compatible library (that is to say, among other things, a library that works in Jest or Node-based test runners), this is quite bad!

@bugzpodder bugzpodder added this to the 3.2 milestone Aug 11, 2019
@dallonf
Copy link
Contributor Author

dallonf commented Sep 18, 2019

Oh wow I just noticed this is still around - um, does anyone know if this is still relevant? I haven't used CRA in a little while. cc @ianschmitz @bugzpodder just because you've looked at this in the past

@ianschmitz ianschmitz modified the milestones: 3.3, 3.4 Dec 5, 2019
@iansu iansu modified the milestones: 3.4, 3.5 Feb 14, 2020
@dallonf
Copy link
Contributor Author

dallonf commented Sep 8, 2020

I'm gonna go ahead and close this because I simply don't remember the context well enough to resolve the conflicts. Sorry for all the going in circles here!

@dallonf dallonf closed this Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants