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 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:The error is caused by the following line in the
bundled.js
:What is the expected behavior?
No response
What do you see instead?
No response
Additional information
No response