(已解决)报错:Invalid options object. options has an unknown property ‘disableHostCheck‘

问题来源

在进行vue2项目打包上线时需要更改vue.config.js文件。

const { defineConfig } = require('@vue/cli-service');
module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    host: '0.0.0.0', // 允许外部访问
    port: 7000,       // 使用端口7000
    disableHostCheck: true, // 禁用主机检查,允许外部访问
  }
});


解决方法

报错信息:

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 

翻译:

无效的选项对象。使用与API模式不匹配的选项对象初始化了Dev Server。
-选项有一个未知属性'disableHostCheck'。这些属性是有效的:
对象{allowedHosts?,你好吗?,客户端?,压缩?, devMiddleware ?,头?, historyApiFallback ?、主机吗?,热吗?, http2 ?, https ?, ipc ?, liveReload ?, magicHtml ?, onAfterSetupMiddleware ?, onBeforeSetupMiddleware ?, onListening ?、开放的吗?、港口吗?、代理吗?,服务器?, setupExitSignals ?, setupMiddlewares ?、静态?, watchFiles ?, webSocketServer ?}
ValidationError:无效选项对象。使用与API模式不匹配的选项对象初始化了Dev Server。
-选项有一个未知属性'disableHostCheck'。这些属性是有效的:
对象{allowedHosts?,你好吗?,客户端?,压缩?, devMiddleware ?,头?, historyApiFallback ?、主机吗?,热吗?, http2 ?, https ?, ipc ?, liveReload ?, magicHtml ?, onAfterSetupMiddleware ?, onBeforeSetupMiddleware ?, onListening ?、开放的吗?、港口吗?、代理吗?,服务器?, setupExitSignals ?, setupMiddlewares ?、静态?, watchFiles ?, webSocketServer ?}

根据报错信息我们可以得知:webpack-dev-server的API已经更新禁用主机检查的disableHostCheck。所以无法使用,并为我们提供了allowedHosts等选项。

下面是进行修改后的代码:

const { defineConfig } = require('@vue/cli-service');

module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    host: '0.0.0.0',
    port: 7000,
    allowedHosts: 'all', // 允许所有主机访问
  }
});

修改后正常运行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值