bun icon indicating copy to clipboard operation
bun copied to clipboard

bun build --compile with puppeteer. but bun run works well

Open txthinking opened this issue 10 months ago • 4 comments

What version of Bun is running?

0.8.1

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

a.js

import fs from 'node:fs';
import os from 'node:os';
import puppeteer from "puppeteer";

console.log(111)

bun add puppeteer

package.json

{ "dependencies": { "puppeteer": "^21.1.1" } }
bun build a.js --compile
./a

What is the expected behavior?

111

What do you see instead?

53899 |     }
53900 |   }
53901 | }
53902 | 
53903 | 
53904 | class CDPClientAdapter extends BidiMapper.EventEmitter {
                                  ^
TypeError: undefined is not an object (evaluating 'BidiMapper.EventEmitter')
      at compiled://root/a:53904:31

Additional information

bun run works well

txthinking avatar Sep 04 '23 15:09 txthinking

Is there any solution for this problem yet? I'm facing the same issue.

Makaran21 avatar Mar 12 '24 17:03 Makaran21

If I use require instead of import, the code works.

Working code,

const puppeteer = require("puppeteer");

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto("https://example.com/");
  console.log(await page.title());
  await browser.close();
})();

Command line,

bun build scrape.js --outfile scrape --target node --compile

Non working code,

import puppeteer from "puppeteer";

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto("https://example.com/");
  console.log(await page.title());
  await browser.close();
})();

Error,

 ./scrape                                                    
17661 |       adapter.close();
17662 |     }
17663 |   }
17664 | }
17665 | 
17666 | class CDPClientAdapter extends BidiMapper.EventEmitter {
                                       ^
TypeError: undefined is not an object (evaluating 'BidiMapper.EventEmitter')
      at /$bunfs/root/scrape:17666:32

entrptaher avatar Apr 02 '24 08:04 entrptaher

1.1.3 the same problem

YuziO2 avatar Apr 09 '24 09:04 YuziO2

I can confirm that this still is an issue in bun version 1.1.3

RifkiSalim avatar Apr 09 '24 10:04 RifkiSalim

Same here, still broken on 1.1.4

CristianPi avatar Apr 17 '24 00:04 CristianPi

Still broken on v1.1.6

dulranga avatar May 01 '24 08:05 dulranga