npm 打包项目报错:npm ERR! code ELIFECYCLE
1、以下是Terminal详细报错信息:
D:\xxx\Workspace\WebstormProjects\vue\vue_demo>npm run build
> vue_demo@1.0.0 build D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo
> node build/build.js
- building for production...(node:21224) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:21224) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'chmod' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'cp' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'dirs' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'pushd' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'popd' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'echo' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'tempdir' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'pwd' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'exec' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'ls' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'find' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'grep' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'head' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'ln' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'mkdir' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'rm' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'mv' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'sed' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'set' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'sort' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'tail' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'test' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'to' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'toEnd' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'touch' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'uniq' of module exports inside circular dependency
(node:21224) Warning: Accessing non-existent property 'which' of module exports inside circular dependency
D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\node_modules\webpack\lib\webpack.js:19
throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
^
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.output has an unknown property 'output'. These properties are valid:
object { auxiliaryComment?, chunkFilename?, crossOriginLoading?, jsonpScriptType?, chunkLoadTimeout?, devtoolFallbackModuleFilenameTemplate?, devtoolLineToLine?, devtoolModuleFilenameTe
mplate?, filename?, hashDigest?, hashDigestLength?, hashFunction?, hashSalt?, hotUpdateChunkFilename?, hotUpdateFunction?, hotUpdateMainFilename?, jsonpFunction?, library?, libraryTarget?,
libraryExport?, path?, pathinfo?, publicPath?, sourceMapFilename?, sourcePrefix?, strictModuleExceptionHandling?, umdNamedDefine? }
-> Options affecting the output of the compilation. `output` options tell webpack how to write the compiled files to disk.
at webpack (D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\node_modules\webpack\lib\webpack.js:19:9)
at D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\build\build.js:19:3
at next (D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\node_modules\rimraf\rimraf.js:83:7)
at CB (D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\node_modules\rimraf\rimraf.js:119:9)
at D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\node_modules\rimraf\rimraf.js:145:14
at FSReqCallback.oncomplete (fs.js:175:21) {
validationErrors: [
{
keyword: 'anyOf',
dataPath: '.output',
schemaPath: '#/properties/output/anyOf',
params: {},
message: 'should match some schema in anyOf',
schema: [Array],
parentSchema: [Object],
data: [Object],
children: [Array]
}
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vue_demo@1.0.0 build: `node build/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vue_demo@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Xu\AppData\Roaming\npm-cache\_logs\2020-07-11T03_05_47_251Z-debug.log
D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo>npm run build
> vue_demo@1.0.0 build D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo
> node build/build.js
- building for production...(node:17756) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:17756) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'chmod' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'cp' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'dirs' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'pushd' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'popd' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'echo' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'tempdir' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'pwd' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'exec' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'ls' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'find' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'grep' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'head' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'ln' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'mkdir' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'rm' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'mv' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'sed' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'set' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'sort' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'tail' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'test' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'to' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'toEnd' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'touch' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'uniq' of module exports inside circular dependency
(node:17756) Warning: Accessing non-existent property 'which' of module exports inside circular dependency
D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\node_modules\webpack\lib\webpack.js:19
throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
^
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.output has an unknown property 'output'. These properties are valid:
object { auxiliaryComment?, chunkFilename?, crossOriginLoading?, jsonpScriptType?, chunkLoadTimeout?, devtoolFallbackModuleFilenameTemplate?, devtoolLineToLine?, devtoolModuleFilenameTe
mplate?, filename?, hashDigest?, hashDigestLength?, hashFunction?, hashSalt?, hotUpdateChunkFilename?, hotUpdateFunction?, hotUpdateMainFilename?, jsonpFunction?, library?, libraryTarget?,
libraryExport?, path?, pathinfo?, publicPath?, sourceMapFilename?, sourcePrefix?, strictModuleExceptionHandling?, umdNamedDefine? }
-> Options affecting the output of the compilation. `output` options tell webpack how to write the compiled files to disk.
at webpack (D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\node_modules\webpack\lib\webpack.js:19:9)
at D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\build\build.js:19:3
at next (D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\node_modules\rimraf\rimraf.js:83:7)
at CB (D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\node_modules\rimraf\rimraf.js:119:9)
at D:\OneDrive\Workspace\WebstormProjects\vue\vue_demo\node_modules\rimraf\rimraf.js:145:14
at FSReqCallback.oncomplete (fs.js:175:21) {
validationErrors: [
{
keyword: 'anyOf',
dataPath: '.output',
schemaPath: '#/properties/output/anyOf',
params: {},
message: 'should match some schema in anyOf',
schema: [Array],
parentSchema: [Object],
data: [Object],
children: [Array]
}
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vue_demo@1.0.0 build: `node build/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vue_demo@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Xu\AppData\Roaming\npm-cache\_logs\2020-07-11T03_08_14_241Z-debug.log
2、下面还原一下报错时的背景
在学习Vue的过程中,之前都是使用静态服务器工具包发布的。一直都没有问题。命令如下:
0) npm install -g serve
1) serve dist
2) 访问:http://localhost:5000
后来,尝试使用动态web服务器(Tomcat)发布项目,打包时就报错了。以下是我的操作步骤:
0) 修改build/webpack.prod.conf.js
output:{
publicPath:'/vue_demo/' // 打包文件夹的名称
}
1) npm run build就会出现标题所示的错误。
3、定位和总结
- 根据报错信息中的
WebpackOptionsValidationError
为关键字百度到了文章,猜到可能是webpack配置出了问题。找了以下output
的publicPath
属性写成了public
。我丢。。。 - 引以为戒!