问题:
npm run dev
> webpack-first@1.0.0 dev /Users/xiexin/project/webpack-first
> npx webpack --mode=development
/Users/xiexin/project/webpack-first/node_modules/.pnpm/registry.npmmirror.com+webpack-cli@3.3.10_webpack@4.41.5/node_modules/webpack-cli/bin/cli.js:281
throw err;
^
TypeError: Cannot read property 'tap' of undefined
at HtmlWebpackPlugin.apply (/Users/xiexin/project/webpack-first/node_modules/.pnpm/registry.npmmirror.com+html-webpack-plugin@5.5.0_webpack@4.41.5/node_modules/html-webpack-plugin/index.js:40:31)
at webpack (/Users/xiexin/project/webpack-first/node_modules/.pnpm/registry.npmmirror.com+webpack@4.41.5_webpack-cli@3.3.10/node_modules/webpack/lib/webpack.js:51:13)
at processOptions (/Users/xiexin/project/webpack-first/node_modules/.pnpm/registry.npmmirror.com+webpack-cli@3.3.10_webpack@4.41.5/node_modules/webpack-cli/bin/cli.js:272:16)
at /Users/xiexin/project/webpack-first/node_modules/.pnpm/registry.npmmirror.com+webpack-cli@3.3.10_webpack@4.41.5/node_modules/webpack-cli/bin/cli.js:364:3
at Object.parse (/Users/xiexin/project/webpack-first/node_modules/.pnpm/registry.npmmirror.com+yargs@13.2.4/node_modules/yargs/yargs.js:567:18)
at /Users/xiexin/project/webpack-first/node_modules/.pnpm/registry.npmmirror.com+webpack-cli@3.3.10_webpack@4.41.5/node_modules/webpack-cli/bin/cli.js:49:8
at Object.<anonymous> (/Users/xiexin/project/webpack-first/node_modules/.pnpm/registry.npmmirror.com+webpack-cli@3.3.10_webpack@4.41.5/node_modules/webpack-cli/bin/cli.js:366:3)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object.<anonymous> (/Users/xiexin/project/webpack-first/node_modules/.pnpm/registry.npmmirror.com+webpack@4.41.5_webpack-cli@3.3.10/node_modules/webpack/bin/webpack.js:156:2)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47
ELIFECYCLE Command failed with exit code 1.
原因:html-webpack-plugin版本过高,使用的是^5.0.0
解决方案:删除插件重装,重装时指定插件版本,降为4.0.0后解决。
npm install html-webpack-plugin@4.0.0 -D