技术帝的平台展示,网站建设、网站推广、SEO技术、网站优化、电子商务推广、平面美工和软件测试等技术干货分享。

webpack [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future

建站技术 abel-lan 59℃ 0评论

概述

webpack报[DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning,是由于webpack升级到5.x版本后导致的,可尝试更新引起出错的包到最新版本。如果使用的插件没有新版本解决该问题时,只能弃用该包或者换用其他包。

问题描述

将webpack升级到5.18.0后,使用imagemin-webpack-plugin时报警告信息如下:

[DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
        Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
        Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
webpack报 [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning
webpack报 [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning

解决过程

该问题虽然只是imagemin-webpack-plugin包执行时报警告信息,程序能执行完,功能也能实现。但对于我这完美主义者,看到该错误,当然要尽力解决。

通过查找资料,发现该错误是由于webpack升级到5.x版本后,imagemin-webpack-plugin没有同步跟进升级导致。

由于imagemin-webpack-plugin没有针对该问题发布新的版本,我们也无法通过升级包来解决该问题。查找该包Github项目文档,有人建议改用image-minimizer-webpack-plugin包,点击查看

解决方法:

  1. 等作者发布新版本修复该问题
  2. 改用其他包,比如image-minimizer-webpack-plugin
  3. 忽视该警告,反正功能不受影响,等到真不能用时再换其他包

扩展:html-webpack-plugin报同样错误

在查找资料时,网上大部分都是使用webpack时html-webpack-plugin报同样错误([DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future)。

webpack报错原因为为html-webpack-plugin这个包导致的⚠️信息,github issue

解决方法

升级html-webpack-plugin到最新版本,或者下一个版本。命令为:

npm install --save-dev html-webpack-plugin@next

转载请注明:半亩方塘 » webpack [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future

赞 (10)支付宝扫码打赏微信扫码打赏分享
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址