1. 程式人生 > 其它 >Vue3 webpack 報錯:options has an unknown property 'hotOnly'. These properties are valid

Vue3 webpack 報錯:options has an unknown property 'hotOnly'. These properties are valid

0x00 問題描述

版本是vue3,執行npm run serve的時候報錯:

 INFO  Starting development server...
 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 'hotOnly'. 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 'hotOnly'. 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 (X:\xxx\xxx\admin\node_modules\webpack-dev-server\node_modules\schema-utils\dist\validate.js:115:11)
    at new Server (X:\xxx\xxx\admin\node_modules\webpack-dev-server\lib\Server.js:231:5)
    at serve (X:\xxx\xxx\admin\node_modules\@vue\cli-service\lib\commands\serve.js:185:20)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

vue.config.js的程式碼是這樣的:

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  devServer: {
    open: true,
    host: 'localhost',
    port: '8081',
    https: false,
    hotOnly: false,
    proxy: {
      '/api': {
        target: 'http://192.168.99.100:8001',
        changeOrigin: true,
        pathRewrite: {
          '^/user': ''
        }
      }
    }
  }
})

0x01 解決方案

hotOnly: false,

改成

hot: "only"

重啟執行npm run serve發現不報錯了

0x02 參考文章

https://stackoverflow.com/questions/69102254/webpack-options-has-an-unknown-property-hotonly-invalid-options-object-dev-s