-
-
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
Disk cache + asset module regression in v5.72.0 #16160
Comments
I think you have outdated cache, ideally you should remove cache when you update webpack, maybe we should do it on our side (i.e. store version in cache and invalidate it when version changed), when you remove old cache is it help? |
I deleted the cache after doing the webpack upgrade though, it was the same version of webpack ( |
/cc @vankop |
I've also noticed this issue affecting some of our builds that use a cache produced in CI and re-used on subsequent CI runs. For us, it seems to happen particularly when trying to use an SVG asset from the cache. We have approximately the same error message except the asset comes through the image minimizer plugin
|
@ryanwilsonperkin hm, we can have a bug in |
Hoping to yes, I haven't been able to reproduce the bug yet unfortunately |
https://github.com/webpack/webpack/blob/main/lib/asset/AssetModulesPlugin.js#L186, hm, filename was lost, what is the version of |
Interestingly it doesn't seem like it's the filename that's getting lost, it's the |
@alexander-akait managed to get a minimal reproduction here: https://github.com/ryanwilsonperkin/webpack-16160 |
Further discovery, by dropping a couple of console logs in the |
Interestingly, if I install the |
Thank you for the report, I will look at this soon, I think bug somewhere in |
I found it buggy only when content of a file was changed in loader, looks like somewhere bug in webpack... continue investigation |
Another intresting thing, if you will use |
When we do code generation we store only (https://github.com/webpack/webpack/blob/main/lib/Compilation.js#L3326):
I.e. no With Not sure why we do it, need advice from @sokra Also if we change order here https://github.com/webpack/webpack/blob/main/lib/ChunkGraph.js#L620, i.e. Also we can alway |
While I appreciate that this might give us the flexibility of not being bound to the bundler, we're already heavily invested in using the bundler for features like this and wouldn't be likely to change all of our image references to URL-based approaches. It seems like that wouldn't work for |
Can you clarify? Anyway I marked it as a bug, because we should fix it |
In the case of
Thanks! I'm also looking into it, although I'm new to the webpack source code |
No, try |
What if i bundled images in a library with rollup? I just want to put all of images on CDN. But it seems that part of image's url is not replaced to correct publicpath by using webpack. |
You can set the public path at runtime or via config |
// library A dist Sorry to bother you again. But when i bundled my application with webpack, I just can choose preserve "import.meta.url" or resolve it. How can i make publicPath replace it correctly? |
We have the special thing - https://webpack.js.org/guides/public-path/#on-the-fly, it should work, try it |
It's not just the url matter. Webpack will not output library A's assets to dist directory if there is no import statement. Thus, library A's assets is missing and uploading it to CDN is obviously a mistake. |
Looks like I faced same bug I have import import airplane from './assets/airplane_gradient.svg'; Loader for svg looks like this: {
test: /\.(png|jpg|gif|svg|webp|jp2|jxr|eot|ttf|woff|woff2|mp4|webm)$/,
type: 'asset/resource',
resourceQuery: /^(?!\?react-svg$).*/,
} and issue looks like this
|
@alexander-akait I've been able to isolate this further and I believe this is a bug in Webpack and not in the I've updated my example repo to replace that plugin with a simple loader that just does the following: // Naive loader that just returns a constant static SVG placeholder
module.exports = function loader(content) {
return '<svg></svg>';
} Using this, we still get the same error message after building, modifying the svg file, and then building again |
@ryanwilsonperkin Thank you for your PR, we will review soon |
Bug report
What is the current behavior?
Webpack throws this error when using asset modules + disk caching:
The build works fine the first time, but then when making a change to the source and rebuilding it throws this error.
If the current behavior is a bug, please provide the steps to reproduce.
I'm really struggling to reproduce this outside of our app, it seems very nuanced and even the conditions to consistently reproduce are difficult.
After some debugging I determined the source of the regression was this change: #15515
The error is getting thrown here:
webpack/lib/asset/AssetModulesPlugin.js
Line 186 in 9fcaa24
module.buildInfo.filename
andcodeGenResult.data
areundefined
.Adding some logs to that line, the value of
codeGenResult
is:and the value of
module
is:The asset module rule in the webpack config we're using is:
Maybe this info is enough to provide some clues as to what's going wrong, but also happy to provide more info or debug output!
What is the expected behavior?
It should not throw an error.
Other relevant information:
webpack version:
5.72.0
Node.js version:
16.16.0
Operating System: MacOS
Additional tools:
The text was updated successfully, but these errors were encountered: