安装 compression webpack plugin 报错:Cannot read property ‘tapPromise‘ of undefined

安装 compression webpack plugin 报错:Cannot read property ‘tapPromise’ of undefined

@vue/cli-service: 4.5.0
webpack: 4

默认安装 compression-webpack-plugin 插件,会自动安装最新版, 而最新版本不兼容问题,在运行项目时导致报错:Cannot read property ‘tapPromise’ of undefined;

报错

ERROR  TypeError: Cannot read property 'tapPromise' of undefined
TypeError: Cannot read property 'tapPromise' of undefined
    at D:\my-project\node_modules\compression-webpack-plugin\dist\index.js:414:39
    at SyncHook.eval [as call] (eval at create (D:\my-project\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:7:1)
    at SyncHook.lazyCompileHook (D:\my-project\node_modules\tapable\lib\Hook.js:154:20)
    at Compiler.newCompilation (D:\my-project\node_modules\webpack\lib\Compiler.js:630:30)
    at D:\my-project\node_modules\webpack\lib\Compiler.js:667:29
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\my-project\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (D:\my-project\node_modules\tapable\lib\Hook.js:154:20)
    at Compiler.compile (D:\my-project\node_modules\webpack\lib\Compiler.js:662:28)
    at D:\my-project\node_modules\webpack\lib\Watching.js:77:18
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\my-project\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:24:1)
    at AsyncSeriesHook.lazyCompileHook (D:\my-project\node_modules\tapable\lib\Hook.js:154:20)
    at Watching._go (D:\my-project\node_modules\webpack\lib\Watching.js:41:32)
    at D:\my-project\node_modules\webpack\lib\Watching.js:33:9
    at Compiler.readRecords (D:\my-project\node_modules\webpack\lib\Compiler.js:529:11)
    at new Watching (D:\my-project\node_modules\webpack\lib\Watching.js:30:17)
    at Compiler.watch (D:\my-project\node_modules\webpack\lib\Compiler.js:244:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ums_web@0.1.0 serve:test: `vue-cli-service serve --mode test`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ums_web@0.1.0 serve:test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\node\node-global\npm-cache\_logs\2022-04-01T06_33_28_173Z-debug.log

解决

使用降级版本 v6.1.1, 解决了这个问题

npm install compression-webpack-plugin@6.1.1 --save-dev

遇到了新问题

warning
Conflict: Multiple assets emit different content to the same filename js/.gz

在这里插入图片描述

这个问题是降级到 v6.1.1 这个版本后, npm run build 时候,发出警告信息,
理论上来说警告是可以忽略的,但是这一出出一片实在心里难受,所以再来解决下这个问题;
其实不解决,生成无效的gzip文件,还是要解决的。
这个警告的意思是,不同的文件都生成的文件是js/.gz, 其实就是在 path 目录(js/)下生成的文件都是.gz文件;

解决

官方给的filename配置是: filename: '[path].gz[query]' 生成的是同名文件.gz, 然后 改成 filename: '[path][base].gz'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

了 义

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值