vue.config.js的配置:
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
lintOnSave: false,
transpileDependencies: true,
devServer: {
open: true,
port: 9876,
disableHostCheck: true,
https: false,
proxy: {
'/api': {
target: 'http://localhost:8000',
ws: true,
changeOrigin: true,
pathRewrite: {
"/api": ''
}
}
},
},
})
报错信息:
[1%] setup (initialize)
ERROR 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 'disableHostCheck'. 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? }
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 'disableHostCheck'. 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? }
at validate (H:\vsCode\hello\vue\user_manager\node_modules\webpack-dev-server\node_modules\schema-utils\dist\validate.js:115:11)
at new Server (H:\vsCode\hello\vue\user_manager\node_modules\webpack-dev-server\lib\Server.js:232:5)
at serve (H:\vsCode\hello\vue\user_manager\node_modules\@vue\cli-service\lib\commands\serve.js:183:20)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
不配置disableHostCheck能正常启动
为啥?
v3:
module.exports = {
devServer: {
disableHostCheck: true,
},
};
v4:
module.exports = {
devServer: {
allowedHosts: "all",
},
};
devServer.disableHostCheck配置项用于配置是否关闭用于 DNS 重绑定的 HTTP 请求的 HOST 检查。 DevServer 默认只接受来自本地的请求,关闭后可以接受来自任何 HOST 的请求。 它通常用于搭配--host 0.0.0.0使用,因为你想要其它设备访问你本地的服务,但访问时是直接通过 IP 地址访问而不是 HOST 访问,所以需要关闭 HOST 检查。
所以配置一下host试试,参考一下下面的,便于理解
参考一下这个
devServer: { // 搭配 webpack-dev-server 使用
//项目构建后的路径
contentBase: resolve(__dirname, 'build'),
// 启动gzip压缩
compress: true,
port: 3000, //端口号
open: true, //自动打开浏览器
host: '0.0.0.0',
disableHostCheck: true, // 绕过主机检查
allowedHosts: // 使用localhost 127.0.0.1 默认可以访问
'host.com', // 通过此选项,您可以将允许访问开发服务器的服务列入白名单。
]
proxy: { // 代理指定url (要避开代理 devSever 与 浏览器的请求)
'/api': {
target:"http://localhost:8088",
ws: true,
changeOrigin: true
}
}
}
版本不匹配,也就是说webpack的版本,与你的config的配置字段不对应,有很多字段舍弃或者封装,或者更换,参考一下
解决没有楼主?