我正在尝试在 webpack 中使用两种配置,但是我尝试的任何方式都失败了,我总是收到以下消息:类型错误:无法读取未定义的属性“tap”在docs 中,它说它是受支持的,即使有一组函数:您可以导出多个配置(自 webpack 3.1.0 起支持多个功能),而不是导出单个配置对象/函数。运行 webpack 时,所有配置都已构建。我正在使用webpack@4.31.0和webpack-cli@3.3.2。这是错误:$ webpack --info-verbosity verboseC:\Users\...\node_modules\webpack-cli\bin\cli.js:281 compiler.hooks.beforeRun.tap("WebpackInfo", compilation => { ^TypeError: Cannot read property 'tap' of undefined at processOptions (C:\Users\...\node_modules\webpack-cli\bin\cli.js:281:31) at yargs.parse (C:\Users\...\node_modules\webpack-cli\bin\cli.js:373:3) at Object.parse (C:\Users\...\node_modules\yargs\yargs.js:567:18) at C:\Users\...\node_modules\webpack-cli\bin\cli.js:49:8 at Object.<anonymous> (C:\Users\...\node_modules\webpack-cli\bin\cli.js:375:3) at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) ...这是我的代码(完整代码在这里):// @ts-checkconst webpack = require('webpack');const path = require('path');const nodeExternals = require('webpack-node-externals');const HtmlWebPackPlugin = require("html-webpack-plugin");module.exports = [clientConfig, serverConfig]; // Error: Array of functions that returns the object fails//module.exports = env => [clientConfig(env), serverConfig(env)]; // Error: Function that return an array of objects fails//module.exports = [clientConfig(), serverConfig()]; // Error: Array of objects fails//module.exports = clientConfig; // OK: The first function alone works//module.exports = serverConfig; // OK: The other function alone worksfunction serverConfig(env) { return { target: 'node', // ... };}function clientConfig(env) { return { target: 'web', //... };}完整代码在这里。更新:相关问题:https : //github.com/webpack/webpack-cli/issues/570#issuecomment-499093581
1 回答

潇潇雨雨
TA贡献1833条经验 获得超4个赞
尝试使用其他版本的 webpack
"webpack": "4.20.2"
我看到有些人报告说他们在使用 webpack 4.30 及更高版本时有这个问题
还尝试使用版本高于“4.0.0-alpha”的 HtmlWebPackPlugin
然后删除你的 package-lock.json 和 node_modules 然后再次运行 npm i
更新:
确保--watch
在命令行中运行
添加回答
举报
0/150
提交
取消