webpack-contrib/compression-webpack-plugin

Restoring failed for CompressionWebpackPlugin; HookWebpackError: this._obj.updateHash is not a function

0xdevalias opened this issue · 5 comments

Bug report

I was recently upgrading a project's build from webpack v4 to webpack v5, and bumping various plugins along the way. I ran into an issue with compression-webpack-plugin where the config that used to work was now throwing the following errors (see below for full stack):

  • Restoring failed for CompressionWebpackPlugin
  • HookWebpackError: this._obj.updateHash is not a function

I haven't looked deeper into things yet to try and figure out what the core issue/solution is, but according to an issue I found on another repo, it looks like defining the options object might be required now, whereas in the past it didn't seem to be:

Actual Behavior

<w> [webpack.cache.PackFileCacheStrategy] Restoring failed for CompressionWebpackPlugin|{"name":"loadable-stats.json","algorithm":"gzip","compressionOptions":{"level":9}} from pack: TypeError: this._obj.updateHash is not a function
99% cache shutdown[webpack-cli] HookWebpackError: this._obj.updateHash is not a function
    at /Users/devalias/dev/REDACTED/node_modules/webpack/lib/HookWebpackError.js:65:13
    at eval (eval at create (/Users/devalias/dev/REDACTED/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:49:1)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
-- inner error --
TypeError: this._obj.updateHash is not a function
    at LazyHashedEtag.toString (/Users/devalias/dev/REDACTED/node_modules/webpack/lib/cache/getLazyHashedEtag.js:35:14)
    at /Users/devalias/dev/REDACTED/node_modules/webpack/lib/cache/PackFileCacheStrategy.js:1217:53
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 50056)
caused by plugins in Cache.hooks.shutdown
TypeError: this._obj.updateHash is not a function
    at LazyHashedEtag.toString (/Users/devalias/dev/REDACTED/node_modules/webpack/lib/cache/getLazyHashedEtag.js:35:14)
    at /Users/devalias/dev/REDACTED/node_modules/webpack/lib/cache/PackFileCacheStrategy.js:1217:53
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 50056)
error Command failed with exit code 2.

Expected Behavior

No error.

How Do We Reproduce?

When my Webpack config initialises the plugin as follows, I get the error:

    // ..snip..
  cache: isProduction
      ? {
          // https://webpack.js.org/configuration/cache/#cachetype
          type: 'filesystem',

          // https://webpack.js.org/configuration/cache/#cachecompression
          // compression: 'gzip',

          // https://webpack.js.org/configuration/cache/#cachebuilddependencies
          buildDependencies: {
            // This makes all dependencies of this file - build dependencies
            config: [__filename],
            // By default webpack and loaders are build dependencies
          },
        }
      : true,
    // ..snip..
  plugins: [
    // ..snip..
    new CompressionPlugin(),
    // ..snip..
  ],
// ..snip..

When I comment out the cache key from my webpack config, it seems to work and not get the error.

Please paste the results of npx webpack-cli info here, and mention other relevant information

⇒ npx webpack-cli info

  System:
    OS: macOS 13.2.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 3.21 GB / 64.00 GB
  Binaries:
    Node: 16.16.0 - ~/.nodenv/versions/16.16.0/bin/node
    Yarn: 1.22.15 - ~/.nodenv/versions/16.16.0/bin/yarn
    npm: 7.20.1 - ~/.nodenv/versions/16.16.0/bin/npm
  Browsers:
    Chrome: 111.0.5563.64
    Safari: 16.3
  Monorepos:
    Yarn Workspaces: 1.22.15

package.json:

// ..snip..
"compression-webpack-plugin": "^10.0.0",
// ..snip..
"webpack": "^5.75.0",
// ..snip..

See Also

Weird, we have a lot of test cases for the cache feature, can you create a reproducible test repository? I feel like you have an incompatibility plugin that emits non webpack sources

Please run npm ls webpack

@alexander-akait Unfortunately I'm no longer working on the codebase where I could originally see/reproduce this. @nathanwaters might be able to, but I suspect he may have gone a different way with the build caching/etc in the end.

I listed the version in my original post though: "webpack": "^5.75.0",

Yeah, but some dependecies can have "webpack": "^4" or don't create assets in valid way, so I need to investigate