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

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 SPSS分类模型实训题步骤
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。