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.

Webpack cache is not invalidated properly after updating one dependency

See original GitHub issue

Bug report

What is the current behavior?

When using webpack cache, I get contaminated build after updating one of dependencies. Specifically, my project has a git dependency, after updating commit ref webpack seems to “merge” old one and new one.

If the current behavior is a bug, please provide the steps to reproduce.

I tried to construct minimal reproducing example for this, but my sample project seem to work fine, but main project does not.

What I do:

  1. Have my project depend on git+https://git.server.local/repo#old-branch-name
  2. In my webpack.config.js I configure ts-loader + babel-loader, asking them to work on dependent repo:
     module: {
         rules: [{
             test:    /\.tsx?$/,
             // also process TS files from the dependency
             exclude: /node_modules(?!\/REPO)/,
             use: [{
                     loader: 'babel-loader',
                     options: require(path.resolve("babel.config.js")),
             }, {
                 loader: 'ts-loader',
                 options: {
                     transpileOnly: true,
                 },
             }]
         }]
     },
    
  3. Build with webpack
  4. In that (dependent) repo, I heavily rewrite some files, and rename others (in particular, bunch of index.js to index.ts).
  5. Run npm i git+https://git.server.local/repo#NEW-branch-name
  6. Build with webpack again

After second build, I actually get a mix of old and new package files from REPO in resulting bundle: one of the new index.ts files imports another module, but webpack actually inserts OLD code for OLD index.js from that module. That old code does not even exist in node_modules/REPO anymore.

If I remove node_modules/.cache/webpack and run build again, I get only NEW code in the bundle.

What is the expected behavior?

webpack should detect that REPO was updated and invalidate its cache for that package.

Other relevant information: webpack version: 5.73.0 Node.js version: 16.13.1 Operating System: macOS 12.4 Monterey Additional tools:

    "babel-loader": "^8.2.5",
    "ts-loader": "^9.3.1",
    "typescript": "^4.8.4",

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
maksbotancommented, Oct 11, 2022

Thank you for the answer!

0reactions
alexander-akaitcommented, Oct 11, 2022

Yes, so you need to use version to detect it, anyway if you have changes in package-json.lock, you can put them in buildDependencies too

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack cache is not invalidated after npm update/install #4543
The Webpack cache is valid even though the packages have changed which leads to errors and/or use of outdated code.
Read more >
should changes in node_modules invalidate the webpack ...
In some kinds of workspaces lib dependencies may appear in node_modules as symlinks - in those cases the dependency can be updated in...
Read more >
Caching - webpack
This guide focuses on the configuration needed to ensure files produced by webpack compilation can remain cached unless their content has changed.
Read more >
Predictable long term caching with Webpack - Medium
As Webpack may allow plugins to change assets after the chunkhash is calculated, and those plugins may not properly update the chunkhash ...
Read more >
Caching in GitLab CI/CD
You use multiple standalone runners (not in autoscale mode) attached to one project without a shared cache. Use only one runner for your...
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