compression-webpack-plugin: TypeError: Cannot read property 'tapPromise' of undefined for webpack 5.6.0
- Operating System: Windows
- Node Version: v14.5.0
- PNPM Version: 5.13.1
- webpack Version: 5.6.0
- compression-webpack-plugin Version: 6.1.1
Expected Behavior
The specified files are compressed.
Actual Behavior
Crash with the following error:
ERROR TypeError: Cannot read property 'tapPromise' of undefined
TypeError: Cannot read property 'tapPromise' of undefined
at C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\compression-webpack-plugin\6.1.1_webpack@5.6.0\node_modules\compression-webpack-plugin\dist\index.js:349:41
at SyncHook.eval [as call] (eval at create (C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\tapable\1.1.3\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:9:1)
at SyncHook.lazyCompileHook (C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\tapable\1.1.3\node_modules\tapable\lib\Hook.js:154:20)
at Compiler.newCompilation (C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\webpack\4.44.2_93ca2875a658e9d1552850624e6b91c7\node_modules\webpack\lib\Compiler.js:630:30)
at C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\webpack\4.44.2_93ca2875a658e9d1552850624e6b91c7\node_modules\webpack\lib\Compiler.js:667:29
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\tapable\1.1.3\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\tapable\1.1.3\node_modules\tapable\lib\Hook.js:154:20)
at Compiler.compile (C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\webpack\4.44.2_93ca2875a658e9d1552850624e6b91c7\node_modules\webpack\lib\Compiler.js:662:28)
at C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\webpack\4.44.2_93ca2875a658e9d1552850624e6b91c7\node_modules\webpack\lib\Compiler.js:321:11
at Compiler.readRecords (C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\webpack\4.44.2_93ca2875a658e9d1552850624e6b91c7\node_modules\webpack\lib\Compiler.js:529:11)
at C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\webpack\4.44.2_93ca2875a658e9d1552850624e6b91c7\node_modules\webpack\lib\Compiler.js:318:10
at eval (eval at create (C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\tapable\1.1.3\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:12:1)
at C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\webpack\4.44.2_93ca2875a658e9d1552850624e6b91c7\node_modules\webpack\lib\CachePlugin.js:50:13
at _next0 (eval at create (C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\tapable\1.1.3\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:8:1)
at eval (eval at create (C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\tapable\1.1.3\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:21:1)
at run (C:\Users\_\Desktop\prmaster\vue\web\common\temp\node_modules\.pnpm\registry.npmjs.org\fork-ts-checker-webpack-plugin\3.1.1\node_modules\fork-ts-checker-webpack-plugin\lib\index.js:248:13)
It appears that the processAssets hook doesn’t exist?
Code
// vue.config.js
/* eslint-disable @typescript-eslint/no-var-requires, no-undef, import/no-extraneous-dependencies */
const zopfli = require('@gfx/zopfli')
const CompressionPlugin = require('compression-webpack-plugin')
module.exports = {
filenameHashing: false,
productionSourceMap: false,
// publicPath: './', // Remove this if html5 history.pushState is used
configureWebpack: config => {
config.output.filename = '[name].js'
config.output.webassemblyModuleFilename = 'webassembly.wasm'
if (typeof process.env.PRODUCTION !== 'undefined')
config.plugins.push(new CompressionPlugin({
test: /\.(js|css|html|svg|wasm)$/,
threshold: 2000,
minRatio: 0.8,
compressionOptions: {
numiterations: 15
},
algorithm(input, compressionOptions, callback) {
return zopfli.gzip(input, compressionOptions, callback)
}
}))
},
chainWebpack: config => {
config.optimization.splitChunks(false)
},
css: {
extract: {
filename: '[name].css'
}
}
}
How Do We Reproduce?
pnpm run serve
Possibly related to #222.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (8 by maintainers)
For anyone running into this issue using create-react-app version 4, it uses webpack 4 so
compression-webpack-plugin
needs to be locked to version6.1.1
.You still use webpack@4, nothing to fix on our side
Same for vue-cli 4.5.11
https://github.com/webpack-contrib/compression-webpack-plugin/releases/tag/v7.0.0
I figured it out. I added the plugin to the wrong section, so it got called with the resolver instead of compiler, sorry!
fork-ts-checker-webpack-plugin
is incompatibility with webpack@5, it patched webpack and do it in wrong way, so I don’t think what we should fix here, another related issue - https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/540