执行npm run build的时候报错怎么办?
[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.configuration.output has an unknown property ‘publiscPath’.
当我们执行npm run build的时候出现以下错误,说明打包不成功。
我们只需要看前面的这两行,意思大概是无法配置对象。Webpack的初始化使用了不匹配的配置对象API模式。配置有一个未知的属性“publiscPath”。
[ webpack-cli] Invalid configuration object. Webpack has been initialized using schema.
- configuration.output has an unknown property 'publiscPath' . These properties
object { assetModuleFilename?, asyncChunks?, auxiliaryComment?, charset?, chnkLoading?, chunkLoadingGlobal?,
clean?, compareBeforeEmit?, crossOriginLoading?, cssChunkFilename?, cssFilenameModuleFilenameTemplate?, devtoolNamespace?, enabledChunkLoadingTypes?, enabledLt?, filename?, globalObject?, hashDigest?, hashDigestLength?, hash
Function?, hashSalt?, hotUpdateChunkFilename?, hotUpdateGlobal?, hotUpdateMainFme?, library?, libraryExport?, libraryTarget?, module?, path?, pathinfo?, publifix?, strictModuleErrorHandling?, strictModuleExceptionHandling?,
trustedTypes?, umdNamedDefine?, uniqueName?, wasmLoading?, webassemblyModuleFil -> Options affecting the output of the compe the compiled files to disk.
1.先检查是否下载好webpack模块,没有下载好的先装好,是不是有漏装的
cnpm install webpack webpack-cli html-webpack-plugin webpack-dev-server -D
2.检查配置生产环境 webpack.prod.js
找到publiscPath,看看为什么没配置对
仔细一看!!!原来是单词没拼写对!
const path = require ( "path" ) ;
const HtmlWebpackPlugin = require ( "html-webpack-plugin" ) ;
module. exports = {
entry : path. resolve ( __dirname, "../src/index.js" ) ,
output : {
filename : "js/app.bundle.js" ,
path : path. resolve ( __dirname, "../build" ) ,
clean : true ,
publiscPath : "/"
} ,
plugins : [
new HtmlWebpackPlugin ( {
template : path. resolve ( __dirname, "../public/index.html" ) ,
hash : true ,
inject : "body" ,
minify : {
removeComments : true ,
removeAttributeQuotes : true ,
collapseWhitespace : true
}
} )
] ,
mode : "production"
}
解决办法:改过来就好啦~
publicPath : "/"
还有很多小伙伴在打包的时候还会出现其他的问题,比如:
vscode会自动联想!!!将plugins误写成Plugin,就会报错。修改过来即可