[Bug]: the order of exports is incorrect when converting ESM to CJS #13785
Labels
area: modules
i: bug
outdated
A closed issue/PR that is archived due to age. Recommended to make a new issue
💻
How are you using Babel?
Programmatic API (
babel.transform
,babel.parse
)Input code
Configuration file name
No response
Configuration
Current and expected behavior
Babel generates this code when converting ESM to CommonJS:
However, the order of exports is incorrect and does not match what native ESM does. For example, ESM code that uses
Object.keys()
on this file will behave differently when converted to CommonJS. The order should be['a', 'b', 'c']
but Babel gives an order of['a', 'c', 'b']
instead. According to the specification, exports must be sorted:Environment
My
package.json
file:Possible solution
I believe Babel should generate
exports.c = exports.b = exports.a = void 0;
instead ofexports.b = exports.c = exports.a = void 0;
here.Additional context
No response
The text was updated successfully, but these errors were encountered: