亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Webpack 多重配置失敗

Webpack 多重配置失敗

翻閱古今 2021-06-17 11:10:47
我正在嘗試在 webpack 中使用兩種配置,但是我嘗試的任何方式都失敗了,我總是收到以下消息:類型錯誤:無法讀取未定義的屬性“tap”在docs 中,它說它是受支持的,即使有一組函數:您可以導出多個配置(自 webpack 3.1.0 起支持多個功能),而不是導出單個配置對象/函數。運行 webpack 時,所有配置都已構建。我正在使用[email protected][email protected]。這是錯誤:$ 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在命令行中運行


查看完整回答
反對 回復 2021-06-18
  • 1 回答
  • 0 關注
  • 145 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號