Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference to external module when bundling jsdom #14011

Open
mquandalle opened this issue Sep 18, 2024 · 2 comments
Open

Reference to external module when bundling jsdom #14011

mquandalle opened this issue Sep 18, 2024 · 2 comments
Labels
bug Something isn't working bundler Something to do with the bundler

Comments

@mquandalle
Copy link

mquandalle commented Sep 18, 2024

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 mquandalle added bug Something isn't working needs triage labels Sep 18, 2024
@mquandalle
Copy link
Author

Maybe similar to #14009 and #11959

@nektro nektro added bundler Something to do with the bundler and removed needs triage labels Sep 19, 2024
@gentlementlegen
Copy link

It should either copy the file alongside the generated index.js like @vercel/ncc does or directly embed the content inside. Worst part is that the link is an absolute path, so if that build was done in another machine, it will use the absolute path of it and is not runnable in any other environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bundler Something to do with the bundler
Projects
None yet
Development

No branches or pull requests

3 participants