Comments (8)
I fixed this in 1.0.0. Can you give it a try and let me know if it works as you'd expect?
from babel-plugin-transform-commonjs.
Hey @coreyfarrell good that you have a workaround using the overrides option. Do you have a proposal for how we should check if something is CJS or not? I could do require/module/exports sniffing, or check the sourceType, but perhaps what you have is fine, just expand it a bit more to:
test: [path.resolve(__dirname, '../node_modules/**')],
plugins: ['transform-commonjs']
This way all node_modules get affected. I'm open to other ideas though on how to support this feature request.
from babel-plugin-transform-commonjs.
Thanks for the response. I'm unable to expand the override test to all node_modules as most that I use from web pages are already ES modules (camelcase is currently the only exception).
I don't have a good proposal for checking if something is CJS. I think looking for module.exports
or exports
variables would probably be best, only inject export default module.exports;
if it's found. I'll try taking a look at this when I get a chance.
from babel-plugin-transform-commonjs.
Works for me, I just moved transform-commonjs
to my common plugins list and verified it no longer breaks ES modules.
from babel-plugin-transform-commonjs.
I've just found a case where this is failing to detect an ES module. I should have a test case soon.
from babel-plugin-transform-commonjs.
We could also set isCJS = false if we find any imports/exports in the Program enter. To avoid the cases where you have something like:
import { require } from 'module'
This actually would not work since isCJS starts false and is set true if any 'CJS' features are detected. Maybe state.esmExports
would be needed. I'm thinking that if ESM export
keyword is found this should block setup of the module
variable and export default module.exports;
. In that case only require()
statements should be processed to replace with import
statements.
from babel-plugin-transform-commonjs.
IMO if we find any clue this is an es module, we need to abort out, or make it a toggleable flag to handle requires.
from babel-plugin-transform-commonjs.
I think the logic is "good enough" for now, and will continue to get better. I'm going to close this since there's nothing else actionable at the moment.
from babel-plugin-transform-commonjs.
Related Issues (13)
- Support top-level return HOT 4
- Duplicate declarations with `exports` re-assignment. HOT 1
- Support for re-exporting ES6 modules HOT 2
- export.default produces invalid javascript HOT 2
- Do not replace exports that aren't in the top level
- IIFE transformed modules are incompatible es module babel plugins HOT 4
- Does this plugin will benefit from proposal top-level-await? HOT 1
- Issue declaring "keyword" at export HOT 3
- Support importsOnly option HOT 1
- Emit export statements only when there are exports HOT 1
- Unable to load react-dom HOT 2
- Release tags HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-plugin-transform-commonjs.