oven-sh / bun

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

Reference to external module when bundling jsdom #14011

Open mquandalle opened 2 days ago

mquandalle commented 2 days ago

What version of Bun is running?

1.1.27+267afa293

What platform is your computer?

Darwin 24.0.0 arm64 arm

What steps can reproduce the bug?

Bundling a script depending on jsdom is broken. To reproduce:

bun install jsdom

# create the script
cat << EOF > jsdom.js                               
import { JSDOM } from 'jsdom';
console.log(JSDOM);
EOF

# bundling
bun build jsdom.js --target=node --outfile=bundled.js

# running (it works)
bun run bundled.js
# > [class JSDOM]

# but it reference an external file read from node_modules/jsdom. Removing this file breaks the bundled script
rm -r node_modules/jsdom
bun run bundled.js
# > error: Cannot find module "/Users/mquandalle/myproject/node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js" from "/Users/mquandalle/myproject/bundled.js" 

The error is caused by the following line in the bundled.js:

  var syncWorkerFile = __require.resolve ? __require.resolve("/Users/mquandalle/myproject/node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js") : null;

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

mquandalle commented 2 days ago

Maybe similar to #14009 and #11959