Transformation issue with es2015
See original GitHub issueIssue Description
I noticed that my commonjs
build included the incorrectly transformed invariant(false)
.
This is incorrect as the import
is being transformed to var _invariant
and invariant
isn’t defined.
The issue can be reproduced in babel repl.
Not sure if invariant(false)
can be converted to (0, _invariant.default)(false)
or whatever.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
babel-plugin-transform-es2015-modules-amd produces ...
Bug Report I have the following package.json : { "name": "watchman", "version": "1.0.0", "description": "Simple watcher for ES6 to AMD ...
Read more >reactjs - Issue when transitioning from "babel-preset-es2015 ...
So I added a .babelrc file and moved the loader options there, and things appear to work just fine now. Still not sure...
Read more >Upgrade to Babel 7
Babel 6's transformations for ES6 modules ran indiscriminately on whatever files it was told to process, never taking into account if the file...
Read more >API - esbuild
There are two main API calls in esbuild's API: transform and build. ... The way to work around this issue is to mark...
Read more >How to transpile ES modules with webpack and Node.js
The documentation for ESM widely covers this topic, ... The @babel/preset-env package will transform all ES2015–ES2020 code to ES5 or ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The plugin reuses
node.callee
in the transformed AST. Babel can not tell they are actually different AST nodes, so only one of them is replaced by commonjs transform. Uset.cloneNode(node.callee)
forprodInvariant
will fix this issue: In my local repo I can not reproduce this issue with the suggested fix.Duplicate AST nodes cause nasty issues like this, as a plugin author, you can use babel-check-duplicated-nodes to ensure the transformed AST does not contain duplicate nodes. Babel uses it, too.
It might be that it just messes with the scope/binding info enough that it doesn’t connect them anymore. Or maybe it tracks through the callExpression, not the callee? Seems like just swapping out the arguments instead of the whole expression might fix it