question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transformation issue with es2015

See original GitHub issue

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:open
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JLHwungcommented, Oct 14, 2021

https://github.com/4Catalyzer/babel-plugin-dev-expression/blob/c734a08b7f3fefc3e7479240013a4d9f907f4429/dev-expression.js#L79-L88

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. Use t.cloneNode(node.callee) for prodInvariant 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.

1reaction
jquensecommented, Jan 10, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found