1. options has an unknown property 'overlay'
client: {
overlay: {
}
}
2. webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
按照報(bào)錯(cuò)提示在代碼中添加相應(yīng)配置即可: 先安裝依賴npm install path-browserify
configuareWebpack: {
resolve: {
alias: {
},
fallback:{
path: require.resolve("path-browserify")
}
}
}
3.ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options has an unknown property 'after'. These properties are valid:
object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, magicHtml?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, server?, setupExitSignals?, setupMiddlewares?, static?, watchFiles?, webSocketServer? }
經(jīng)查閱官方文檔webpack5-devServer,after和before已棄用,分別用middlewares.push
和middlewares.unshift
替代
devServer: {
setupMiddlewares: (middlewares, devServer) => {
if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}
devServer.app.get('/setup-middleware/some/path', (_, response) => {
response.send('setup-middlewares option GET');
});
}
}
4. devServer獲取post傳遞參數(shù)undefined
以前的寫法
// 安裝 body-parser
npm install body-parser
const bodyParser = require(‘body-parser’);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
express 4.X版本不需要額外加載body-parser
const express = require(‘express’);
devServer.app.use(express.json());
devServer.app.use(express.urlencoded({
extended: true
}));