杳然(❁´◡`❁)*✲゚* 2022-03-07 17:00 采纳率: 100%
浏览 2366
已结题

Vue3.x在vue.config.js配置disableHostCheck: true后程序启动报错

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能正常启动
为啥?

  • 写回答

4条回答 默认 最新

  • ss0xt 2022-04-26 14:20
    关注

    v3:

    module.exports = {
    devServer: {
    disableHostCheck: true,
    },
    };
    v4:

    module.exports = {
    devServer: {
    allowedHosts: "all",
    },
    };

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 5月5日
  • 已采纳回答 4月27日
  • 创建了问题 3月7日

悬赏问题

  • ¥15 Python程序,深度学习,有偿私
  • ¥15 扫描枪扫条形码出现问题
  • ¥15 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开