Dev Server says "Upgrade Required", browser has CORS-issues since Vite version 2.9.0
See original GitHub issueDescribe the bug
Hello Vite!
I’m the author of this plugin for Vite and Silverstripe CMS, this plugin for CakePHP, and I use this configuration.
Until now, everything worked fine with the dev server, hot module replacement etc. However, after running yarn upgrade
i noticed that the dev server is not working anymore. The browser is complaining about cors-issues - see screenshot below:
I tried to downgrade vite step by step and the issue seems to be present from version 2.9.0
. Is there any configuration that I missed which has to be present?
As I use Vite in php apps, I serve my PHP with MAMP (e.g. https://my-domain.local
) and the js from vite gets served by the vite dev server from localhost:3000
, through this configuration:
server: {
hmr: {
protocol: 'ws',
host: 'localhost',
port: 3000,
},
},
When accessing one of the localhost urls, I now only get an Upgrade required
warning. In the network tab I see that the browser got a http 426
response from the dev server, similar to this issue: https://github.com/vitejs/vite/issues/5770
However, reinstalling did not solve the problem. I have now locked the version in package.json
to vite 2.8.6
which works for now, but I hope I will be able to keep Vite up to date in the future.
If this is a bug, I am happy to help with further information. Otherwise it would be great to get a hint about how to solve this problem.
Reproduction
https://github.com/brandcom/silverstripe-vite
System Info
System:
OS: macOS 12.3.1
CPU: (8) arm64 Apple M1
Memory: 158.61 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 17.0.1 - /opt/homebrew/bin/node
Yarn: 1.22.18 - /opt/homebrew/bin/yarn
npm: 8.3.0 - /opt/homebrew/bin/npm
Browsers:
Brave Browser: 102.1.39.120
Chrome: 102.0.5005.115
Firefox: 101.0.1
Safari: 15.4
npmPackages:
@vitejs/plugin-legacy: ^1.8.2 => 1.8.2
@vitejs/plugin-vue: ^2.3.3 => 2.3.3
vite: 2.8.6 => 2.8.6
Used Package Manager
yarn
Logs
vite --debug
vite:config bundled config file loaded in 18.10ms +0ms
vite:config using resolved config: {
vite:config plugins: [
vite:config 'vite:pre-alias',
vite:config 'alias',
vite:config 'vite:modulepreload-polyfill',
vite:config 'vite:resolve',
vite:config 'vite:html-inline-proxy',
vite:config 'vite:css',
vite:config 'vite:esbuild',
vite:config 'vite:json',
vite:config 'vite:wasm',
vite:config 'vite:worker',
vite:config 'vite:worker-import-meta-url',
vite:config 'vite:asset',
vite:config 'vite:vue',
vite:config 'vite:legacy-env',
vite:config 'vite:define',
vite:config 'vite:css-post',
vite:config 'vite:client-inject',
vite:config 'vite:import-analysis'
vite:config ],
vite:config build: {
vite:config target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
vite:config polyfillModulePreload: true,
vite:config outDir: './public/',
vite:config assetsDir: 'build',
vite:config assetsInlineLimit: 4096,
vite:config cssCodeSplit: true,
vite:config cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
vite:config sourcemap: false,
vite:config rollupOptions: { input: './public_src/main.ts' },
vite:config minify: 'esbuild',
vite:config terserOptions: {},
vite:config write: true,
vite:config emptyOutDir: false,
vite:config manifest: true,
vite:config lib: false,
vite:config ssr: false,
vite:config ssrManifest: false,
vite:config reportCompressedSize: true,
vite:config chunkSizeWarningLimit: 500,
vite:config watch: null,
vite:config commonjsOptions: { include: [Array], extensions: [Array] },
vite:config dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
vite:config },
vite:config server: {
vite:config preTransformRequests: true,
vite:config hmr: { protocol: 'ws', host: 'localhost', port: 3000 },
vite:config fs: { strict: true, allow: [Array], deny: [Array] }
vite:config },
vite:config define: {
vite:config __VUE_OPTIONS_API__: true,
vite:config __VUE_PROD_DEVTOOLS__: false,
vite:config 'import.meta.env.LEGACY': false
vite:config },
vite:config ssr: { external: [ 'vue', '@vue/server-renderer' ] },
vite:config configFile: '/Users/pascalschneider/Sites/xyz.local/vite.config.ts',
vite:config configFileDependencies: [ 'vite.config.ts' ],
vite:config inlineConfig: {
vite:config root: undefined,
vite:config base: undefined,
vite:config mode: undefined,
vite:config configFile: undefined,
vite:config logLevel: undefined,
vite:config clearScreen: undefined,
vite:config server: {}
vite:config },
vite:config root: '/Users/pascalschneider/Sites/xyz.local',
vite:config base: '/',
vite:config resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
vite:config publicDir: '/Users/pascalschneider/Sites/xyz.local/public',
vite:config cacheDir: '/Users/pascalschneider/Sites/xyz.local/node_modules/.vite',
vite:config command: 'serve',
vite:config mode: 'development',
vite:config isProduction: false,
vite:config preview: {
vite:config port: undefined,
vite:config strictPort: undefined,
vite:config host: undefined,
vite:config https: undefined,
vite:config open: undefined,
vite:config proxy: undefined,
vite:config cors: undefined,
vite:config headers: undefined
vite:config },
vite:config env: { BASE_URL: '/', MODE: 'development', DEV: true, PROD: false },
vite:config assetsInclude: [Function: assetsInclude],
vite:config logger: {
vite:config hasWarned: false,
vite:config info: [Function: info],
vite:config warn: [Function: warn],
vite:config warnOnce: [Function: warnOnce],
vite:config error: [Function: error],
vite:config clearScreen: [Function: clearScreen],
vite:config hasErrorLogged: [Function: hasErrorLogged]
vite:config },
vite:config packageCache: Map(0) {},
vite:config createResolver: [Function: createResolver],
vite:config optimizeDeps: {
vite:config esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
vite:config },
vite:config worker: {
vite:config format: 'iife',
vite:config plugins: [
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object]
vite:config ],
vite:config rollupOptions: {}
vite:config }
vite:config } +3ms
vite:deps Hash is consistent. Skipping. Use --force to override. +0ms
vite v2.8.6 dev server running at:
> Local: http://localhost:3000/
> Network: use `--host` to expose
ready in 129ms.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
@passchn it would be helpful if you could review and comment on https://github.com/vitejs/vite/pull/7977, we would like to move forward with this change in v3
Oh, that’s true. It needs
server.hmr
settings.