Persistent caching return stale results when updating resolve.alias
See original GitHub issueBug report
What is the current behavior?
When changing resolve.alias
, affected persistent cache entries are still used instead of being evited.
If the current behavior is a bug, please provide the steps to reproduce.
I’m using the filesystem cache with resolve aliases:
const myAliases = {
"@theme/MyComponent": "/dirname/OLD_COMPONENT.js",
};
module.exports = {
cache: {
type: "filesystem",
},
resolve: { alias: myAliases }
}
Now, let’s change the aliases:
const myAliases = {
"@theme/MyComponent": "/dirname/NEW_COMPONENT.js",
};
module.exports = {
cache: {
type: "filesystem",
},
resolve: { alias: myAliases }
}
When building/running again (dev server or prod), Webpack will keep using the code from OLD_COMPONENT.js
, while it should rather use NEW_COMPONENT.js
When cleaning node_modules/.cache/webpack
, the next build will use NEW_COMPONENT.js
successfully.
What is the expected behavior?
I would expect Webpack to be able to discard cache entries that are affected by the alias changes.
A workaround is to use cache.version
to discard the whole cache when aliases are updated, but this is a bit too aggressive to clean the whole cache for a single alias change.
const myAliases = {
"@theme/MyComponent": "/dirname/NEW_COMPONENT.js",
};
module.exports = {
cache: {
type: "filesystem",
version: md5HashString(myAliases),
},
resolve: { alias: myAliases }
}
Doc says:
Update the version when configuration changed in a way which doesn’t allow to reuse cache.
It is not totally clear to me what configuration changes are handled by webpack, and what configuration changes should we handle in userland. I think it would be nice to have this supported in webpack core as it’s hard to implement in an efficient way in userland.
Other relevant information: webpack version: 5.40 Node.js version: 14.x Operating System: macos sierra Additional tools:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:9 (7 by maintainers)
Top GitHub Comments
No problems here… How you run webpack? If you use webpack-cli we automatically added your configuration as
buildDependencies
https://github.com/webpack/webpack-cli/blob/master/packages/webpack-cli/lib/webpack-cli.js#L1855, so any changes in file will invalidate cache, but if you use external file you need do it manually, also we have https://webpack.js.org/configuration/other-options/#cacheversion for this purposein theory it is possible, here we implement logic for resolving https://github.com/webpack/webpack/blob/master/lib/cache/ResolverCachePlugin.js, also we have hooks for get/store cache