bun icon indicating copy to clipboard operation
bun copied to clipboard

bun build with puppeteer dependency fails

Open EmielM opened this issue 1 year ago • 12 comments

What version of Bun is running?

1.0.3+25e69c71e70ac8a0a88f9cf15b4057bd7b2a633a

What platform is your computer?

Linux 5.4.0-113-generic x86_64 x86_64

What steps can reproduce the bug?

Trying to bun build --target bun a simple script that uses puppeteer 21.3.6 and then build run fails with TypeError: The superclass is not a constructor..

Directly running bun run index.js works as expected. Repro case: https://github.com/EmielM/bun-build-repro

This is probably some issue with puppeteer: if you look at node_modules/puppeteer-core/lib/esm/puppeteer/api/JSHandle.js, you see it's pretty convoluted/generated javascript.

But flagging here as

  • I think puppeteer is not some marginal library :), so will probably impact others
  • shouldn't bun build --target bun --outfile out.js index.js && bun run out.js always be behaviourally identical to bun run index.js in all cases?

What is the expected behavior?

A successful run (generated chrome.png)

What do you see instead?

52593 |   init_Serializer();
52594 | });
52595 | 
52596 | // node_modules/puppeteer-core/lib/esm/puppeteer/bidi/JSHandle.js
52597 | 
52598 | class BidiJSHandle extends JSHandle {
   ^
TypeError: The superclass is not a constructor.
      at /home/emiel/bun-repro/out.js:52598:0

Additional information

No response

EmielM avatar Oct 03 '23 11:10 EmielM

same problem here

LiangNiang avatar Oct 20 '23 05:10 LiangNiang

same

CelyQ avatar Oct 20 '23 05:10 CelyQ

I'm encountering this error message as well. For build target node and bun

mattay avatar Nov 05 '23 12:11 mattay

exactly same problem here..

mibcadet avatar Nov 06 '23 21:11 mibcadet

Same issue here. Do we have an update on this?

devtorello avatar Nov 16 '23 19:11 devtorello

Here's an isolated repro: for this code bun build emits code of the form:

class MyComponent extends React.Component {
  // ...
}
var React, MyComponent_default;
var init_MyComponent = __esm(() => {
  React = __toESM(require_react(), 1);
  MyComponent_default = MyComponent;
});
  • init_MyComponent that initializes React and thus React.Component, is called is called after the class definition.
  • So runtimes crashes after encountering the class ... extends definition, eg in chrome: Uncaught TypeError: Cannot read properties of undefined (reading 'Component')

EmielM avatar Dec 01 '23 13:12 EmielM

Same issue here on bun 1.0.18. Any updates on this? Because of that I cannot dockerize bun. Same with tsx files using puppeteer.

ecosse3 avatar Dec 14 '23 13:12 ecosse3

Same problem here with bun 1.0.26

laurensV avatar Feb 09 '24 11:02 laurensV

same with latest version of bun :/

ChARCOOL avatar Feb 14 '24 22:02 ChARCOOL

Seems to happen with multiple packages, like @solana/web3,js (https://github.com/oven-sh/bun/issues/8925) AWS CDK (https://github.com/oven-sh/bun/issues/3088) and probably more

laurensV avatar Feb 15 '24 15:02 laurensV

same here

Makaran21 avatar Mar 04 '24 08:03 Makaran21

Update: this still happens on the latest bun, basically making it unusable as bundler for web for most react applications, at least where a few old-style components (extends React.Component) are used.

EmielM avatar Apr 09 '24 07:04 EmielM

same, no solution? with supabase auth

Geczy avatar Jun 01 '24 20:06 Geczy

Still happening

113044 |   await client.send("Runtime.releaseObject", { objectId: remoteObject.objectId }).catch((error2) => {
113045 |     debugError(error2);
113046 |   });
113047 | }
113048 | 
113049 | class CdpJSHandle extends JSHandle {
                                   ^
TypeError: The superclass is not a constructor.

for

bun --version
1.1.20

hhimanshu avatar Jul 19 '24 23:07 hhimanshu