一、背景
使用webpack構建項目時報錯:
describe: optionsSchema.definitions.output.properties.path.description,
^
TypeError: Cannot read property 'properties' of undefined
at module.exports (D:\00_git_pull\Mindsphere-Ali\Starter-Service\FleetManager-Lynn\fleetmanager\node_modules\webpack-cli\bin\config-yargs.js:89:48)
at Object.<anonymous> (D:\00_git_pull\Mindsphere-Ali\Starter-Service\FleetManager-Lynn\fleetmanager\node_modules\webpack-dev-server\bin\webpack-dev-server.js:84:40)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:279:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)
二、 原因分析
根據報錯,可以發現,報錯出現在項目文件夾下的node_modules\webpack-cli\bin\config-yargs.js
文件 第89
行。
// webpack-cli 2.1.3 config-yargs.js
"output-path": {
type: "string",
describe: optionsSchema.definitions.output.properties.path.description, //報錯
group: OUTPUT_GROUP,
defaultDescription: "The current directory",
requiresArg: true
},
當前webpack-cli的版本爲2.1.3,當前webpack版本爲4.20.2。查看webpack 的release log,發現
注意: webpack4.20.0以上版本要使用3.1.1版本的webpack-cli
webpack4.20.0發行日志: https://github.com/webpack/webpack/releases/tag/v4.20.0
三、解決辦法
更新webpack-cli到3.1.1及以上版本,執行npm i webpack-cli
;
+ webpack-cli@3.1.2
updated 1 package and audited 22855 packages in 18.32s
安裝最新版3.1.2版本webpacl-cli後,output-path
變爲
"output-path": {
type: "string",
describe: getSchemaInfo("output.path", "description"), //更新部分
group: OUTPUT_GROUP,
defaultDescription: "The current directory",
requiresArg: true
},
再次執行webpack命令打包運行項目,done。
i 「wds」: Project is running at http://localhost:3000/webpack-dev-server/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from D:\00_git_pull\Mindsphere-Ali\Starter-Service\FleetManager-Lynn\fleetmanager\resources\
i 「wdm」: Compiled successfully.