oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.44k stars 2.7k forks source link

react production bundle includes more module wrappers than necessary #12726

Open paperdave opened 2 months ago

paperdave commented 2 months ago

What version of Bun is running?

1.1.20

What platform is your computer?

No response

What steps can reproduce the bug?

import { renderToReadableStream } from "react-dom/server";
console.log([renderToReadableStream]);

bun build input.ts --target=bun

What is the expected behavior?

to not generate this wrapper:

image

What do you see instead?

four references to __commonJS. auditing this manually, there should only be 3

Additional information

There is code to specifically handle the pattern used by react/index.js here

'use strict';

if (process.env.NODE_ENV === 'production') {
  module.exports = require('./cjs/react.production.js');
} else {
  module.exports = require('./cjs/react.development.js');
}

image

it no longer works, likely because the esm wrapper is being injected.

paperdave commented 2 months ago

note: --minify-syntax helps this. but it should not be required