question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Persistent caching return stale results when updating resolve.alias

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
alexander-akaitcommented, Jun 23, 2021

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 purpose

1reaction
alexander-akaitcommented, Jun 24, 2021

Was wondering if Webpack offers any API for imperatively invalidate/manipulate some cache entries.

in 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

The "path" argument must be of type string. Received ... - GitHub
I had not updated to the withSentryConfig yet, I wanted to determine if 7.8.0 was the cause. It could have been a caching...
Read more >
lru-cache - npm
Start using lru-cache in your project by running `npm i lru-cache`. ... The cache.has() method will always return false for stale items.
Read more >
Configuring the Apollo Client cache - Apollo GraphQL Docs
If true , the cache returns an identical ( === ) response object for every execution of the same query, as long as...
Read more >
Caching – Vercel Docs
STALE : The response that was served from the edge was stale. A background request to the origin server was made to get...
Read more >
7 Managing Performance Tuning and Query Caching
As updates occur on the back-end databases, the query cache entries can become stale. Therefore, you must periodically remove entries from the query...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found