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

Webpack workaround #22605

Merged
merged 10 commits into from
Sep 24, 2024
Merged

Conversation

seanmorris
Copy link
Contributor

@seanmorris seanmorris commented Sep 22, 2024

The string of code new URL('./', import.meta.url) causes webpack to try and resolve the URL, which causes problems for downstream users who are using that bundler:

webpack/webpack#16878

electric-sql/pglite#328

This PR replaces new URL('./', import.meta.url) with new URL('./', Object(import.meta).url), which is a workaround for this behavior.

src/shell.js Outdated Show resolved Hide resolved
@sbc100
Copy link
Collaborator

sbc100 commented Sep 23, 2024

@seanmorris BTW are you targetting node? If not and you are only targeting that web you might also want to simple remove this code using -sENVIRONMENT=web.

@sbc100
Copy link
Collaborator

sbc100 commented Sep 23, 2024

How does webpack handle fileURLToPath(import.meta.url);? We could do path.dirname(fileURLToPath(import.meta.url); here instead maybe?

@seanmorris
Copy link
Contributor Author

How does webpack handle fileURLToPath(import.meta.url);? We could do path.dirname(fileURLToPath(import.meta.url); here instead maybe?

That works great. Its just new URL(___, import.meta.url) we need to worry about.

@seanmorris
Copy link
Contributor Author

seanmorris commented Sep 24, 2024

@seanmorris BTW are you targetting node? If not and you are only targeting that web you might also want to simple remove this code using -sENVIRONMENT=web.

My project has separate builds for all targets, but not everyone wants to do that. This is for the countless downstream projects that want to publish universal builds.

There are valid reasons for that, too. I need to be VERY careful about the size of my project, php-wasm. I'm publishing separate builds for all targets in cjs & mjs. If I go over a certain limit (100mb total package size), I can't publish my project via CDNs like jsdelivr or unpkg. So far I've solved the problem by splitting the extensions off into their own packages and loading them dynamically as .so files, but not everyone has that luxury. I may need to move cjs into its own release channel. You can see how I'm doing the loading here: https://codepen.io/SeanMorris227/pen/Yzbbrre?editors=1000

I'd really like to maximize interoperability. If there's a roadblock we can remove with a small notation change, then I say we do it, at least until webpack figures their mess out.

I see a LOT of potential in this project for interoperability. If someone wants to re-use code in a webpack project, but can't because of how its been published, that's going to cut the Emscripten userbase significantly.

src/shell.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with comment addressed

src/shell.js Outdated Show resolved Hide resolved
@sbc100 sbc100 enabled auto-merge (squash) September 24, 2024 16:22
@sbc100 sbc100 merged commit 543993e into emscripten-core:main Sep 24, 2024
26 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants