webpack4报错compilation.mainTemplate.applyPluginsWaterfall is not a function

最近在进行webpack4的学习,在进行运行的时候出现了一个问题,通过查找资料最终解决,记录一下

html-webpack-plugin 版本不兼容问题

10% building modules 1/1 modules 0 active(node:15332) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
(node:15332) DeprecationWarning: Tapable.apply is deprecated. Call apply on the plugin directly instead                                                  11% building modules 10/10 modules 0 activeD:\project\webpack\node_modules\html-webpack-plugin\lib\compiler.js:81
        var outputName = compilation.mainTemplate.applyPluginsWaterfall('asset-path', outputOptions.filename, {
                                                  ^

TypeError: compilation.mainTemplate.applyPluginsWaterfall is not a function
    at D:\project\webpack\node_modules\html-webpack-plugin\lib\compiler.js:81:51
    at compile (D:\project\webpack\node_modules\webpack\lib\Compiler.js:296:11)
    at hooks.afterCompile.callAsync.err (D:\project\webpack\node_modules\webpack\lib\Compiler.js:553:14)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\project\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:15:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\project\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at compilation.seal.err (D:\project\webpack\node_modules\webpack\lib\Compiler.js:550:30)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\project\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\project\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at hooks.optimizeAssets.callAsync.err (D:\project\webpack\node_modules\webpack\lib\Compilation.js:1294:35)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\project\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\project\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at hooks.optimizeChunkAssets.callAsync.err (D:\project\webpack\node_modules\webpack\lib\Compilation.js:1285:32)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\project\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\project\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at hooks.additionalAssets.callAsync.err (D:\project\webpack\node_modules\webpack\lib\Compilation.js:1280:36)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\project\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)

原因:是html-webpack-plugin·版本不兼容问题

"webpack":"^4.0.0",
"html-webpack-plugin":"^2.30.1"
//会出现不兼容问题


解决方案:升级到最新版

npm i --save-dev html-webpack-plugin@next
yarn add --dev html-webpack-plugin@next


官方地址:https://github.com/jantimon/html-webpack-plugin
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值