hard-source-webpack-plugin icon indicating copy to clipboard operation
hard-source-webpack-plugin copied to clipboard

Webpack 5.x not supportted, because `compiler.hooks` can not add property

Open hzsrc opened this issue 3 years ago • 5 comments

Expected Behavior

Support webpack 5.x

Actual Behavior

Not supportted.

Is an error being thrown?

Yes, throws an error:

TypeError: Cannot read property 'tap' of undefined
    at Object.exports.tap (D:\proj\h5\node_modules\hard-source-webpack-plugin\lib\util\plugin-compat.js:118:25)
    at new CacheSerializerFactory (D:\proj\h5\node_modules\hard-source-webpack-plugin\lib\CacheSerializerFactory.js:94:18)
    at HardSourceWebpackPlugin.apply (D:\proj\h5\node_modules\hard-source-webpack-plugin\index.js:219:36)
    at createCompiler (D:\proj\h5\node_modules\webpack\lib\webpack.js:71:12)
    at create (D:\proj\h5\node_modules\webpack\lib\webpack.js:118:16)
    at webpack (D:\proj\h5\node_modules\webpack\lib\webpack.js:142:32)
    at f (D:\proj\h5\node_modules\webpack\lib\index.js:41:15)
 

Steps to Reproduce

  • Use webpack 5.24.3
  • Webpack plugins include: new HardSourceWebpackPlugin()

Operating System, Node, and NPM dependency versions

Windows 10
[email protected]
[email protected]

"devDependencies": {
  "babel-core": "^6.26.0",
  "babel-loader": "^7.1.4",
  "babel-preset-env": "^1.6.1",
  "css-loader": "^0.27.0",
  "html-webpack-plugin": "^3.2.0",
  "mini-css-extract-plugin": "^0.4.0",
  "style-loader": "^0.14.0",
  "webpack": "^5.24.3",
  "webpack-cli": "^1.5.3"
},
"dependencies": {
  "lodash": "^4.15.0"
}

hzsrc avatar Mar 30 '21 08:03 hzsrc

In webpack 5.x, the compiler.hooks can not add any property into it.
image

So, when get the hardSourceCacheFactory property in tapable.hooks, it returns undefined: image

hzsrc avatar Mar 30 '21 09:03 hzsrc

Same error: https://github.com/AnomalyInnovations/serverless-bundle/issues/178

hzsrc avatar Mar 30 '21 11:03 hzsrc

@hzsrc What's the update?

amerllica avatar May 22 '21 10:05 amerllica

@amerllica FYI I was able to remove this plugin completely in favor of native Webpack 5 filesystem caching.

This is what I added to my webpack.config.js to enable it:

    cache: {
      type: 'filesystem',
      buildDependencies: {
        config: [__filename]
      }
    },

On the first run of the dev server it populates the cache and takes ~1min, when I re-run it starts up in ~10s.

Also see https://github.com/mzgoddard/hard-source-webpack-plugin/issues/514#issuecomment-687621600

phillipuniverse avatar May 25 '21 14:05 phillipuniverse

@phillipuniverse, Thanks for your comment, my project is so big, very very big, so by using the native Webpack caching system, after the first time, I reduce the re-build time to 1min, I hope to find a way to reduce it below 300ms.

Finally, thanks.

amerllica avatar May 25 '21 14:05 amerllica