-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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 tries to resolve new URL('./', import.meta.url)
to a module and fails or succeeds (both are wrong)
#16878
Comments
Of course, I can also make it "work" if I listen to webpack and create <script src="main.js"></script> Then I get this in the console:
|
Do you want to ignore only
can you clarify, we already do it, or Am I missing something? |
Hi! As mentioned above, webpack should make The current behaviour of Webpack is fantastic and fabulous in the case where The main problem is when it points to a directory. Webpack will try to resolve it as a module. This is wrong, because I think it would be helpful if it would also pass through anything else that it is unable to resolve to an asset, but maybe that gets into something beyond my comprehension of how Webpack works... |
See specifically https://webpack.js.org/guides/asset-modules/#url-assets for the current (good) behaviour of webpack for files referenced with |
yeah, do you want to send a fix - https://github.com/webpack/webpack/blob/main/lib/dependencies/URLPlugin.js#L52? |
Sure! Thanks for the pointer to the relevant code, it would have taken me a lot longer to find that ;-) I'll make a PR... |
@dhdaines let us know if you need any additional guidance. Commenting to keep from getting stale :-) |
Thanks! I haven't had the time to look at this in the last couple weeks, but should have some today, I'll let you know! |
I looked at our code and I am afraid it will be breaking change, anyway I agree with yor and we should do nothing with it (by default as minimum), unfortunately it is not possible to change the logic now (we don't know how many developers can use it and based on our logic it can be used and it will work), anyway we can implement an options for this, i.e. I want:
Firstly I want to start with |
This issue had no activity for at least three months. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Ah, thank you - sorry I didn't get any time to look further into this, I was a bit lost in the code. Having it be an experimental option would make sense to me. Commenting to avoid it getting stale as well! I hope I can look at it this week or next! |
Issue was closed because of inactivity. If you think this is still a valid issue, please file a new issue with additional information. |
i would like to help, but i don't know how to test the code in URLPlugin.js after rewrite |
Just put config case here https://github.com/webpack/webpack/tree/main/test/configCases |
bump |
Bug report
What is the current behavior?
Webpack's resolution of
new URL(..., import.meta.url)
does something unexpected when the target is a directory, which doesn't correspond to what either the browser or Node will do. For comparison, try this in $BROWSER_OF_YOUR_CHOICE:or in Node, create
index.mjs
and run it:In both cases you should see something like:
Webpack does ... something else. See below.
If the current behavior is a bug, please provide the steps to reproduce.
Given the
index.mjs
file above, run:It will fail with an error like this:
(if there is a
package.json
somewhere in a parent directory it will output some other stuff about that, but it will still fail in the same way)I can make it "work" if I initialize the current directory as a module:
This is not what I want, because it will resolve the
new URL
above to the module in the current directory, then bundle whatever it can find in that module. All I wanted was a URL that pointed to the current directory! (and a Pepsi)See the example here: https://github.com/dhdaines/webpack-wasm-test/tree/main/importmeta
What is the expected behavior?
Webpack should just pass
new URL('./', import.meta.url)
through unchanged. It should not try to resolve a directory as a module.Ideally it should also pass through unchanged any other instance of
new URL(..., import.meta.url)
where the target can't be resolved as an asset, since the user might create them after the fact.Other relevant information:
webpack version: ^5.76.3 => 5.76.3
Node.js version: 14.18.2
Operating System: Linux 5.19 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
The text was updated successfully, but these errors were encountered: