Open Guibi1 opened 4 months ago
After more digging, it seems like the final require_react()
is working as intended in the compiled file. However, the only export is export default require_react();
, which only exports a { default: require_react() }. This explains the additional nesting that occurs when the file is imported.
I was unable to find a reliable solution that doesn't imply exporting each keys one by one. (export const { default, version, useState, [...] } = require_react();
)
I managed to work around this by replacing isNodeMode || !mod || !mod.__esModule
to isNodeMode && (!mod || !mod.__esModule)
. Since having the __esModule
marker means that the CJS module is already ESM compatible, and does not need to be wrapped again with a default
.
Relevant stackoverflow answer: https://stackoverflow.com/questions/50943704/whats-the-purpose-of-object-definepropertyexports-esmodule-value-0
What version of Bun is running?
1.1.18+5a0b93523
What platform is your computer?
Ubuntu WSL2 on Win11
What steps can reproduce the bug?
Compile a commonjs file using Bun.
This bug breaks the use of Bun.build, as the resulting file CANNOT be used for named import interchangeably with the original non-compiled file.
In this example, I compile the
react
package fromnode_modules
(make sure to install it), and I then compare the imported module of the compiled react and the untouched react. I expect both to be identical. However, thecompiled
module has and additionnal depth.What is the expected behavior?
What do you see instead?
Additional information
I modified the first line of the outputs to allow proper highlighting.
Possible fix
This issue can probably be fixed by modifying the functions added by the compiler at the start of the file: