question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dev Server says "Upgrade Required", browser has CORS-issues since Vite version 2.9.0

See original GitHub issue

Describe 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:

Bildschirmfoto 2022-06-15 um 10 47 33

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
patak-devcommented, Jun 16, 2022

@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

0reactions
sapphi-redcommented, Jun 16, 2022

Oh, that’s true. It needs server.hmr settings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any solution to solve CORS error in Vite js? [duplicate]
First, you do not need the 'Access-Control-...' headers on the client side. So you can remove these. You can only set CORS on...
Read more >
Fixing CORS problems in local and deploying with Netlify
Vue 3; Vite as development / bundler server; Axios as HTTP client ... A CORS error is any error generated by the browser...
Read more >
Vite on Twitter: " vite@2.9.0 is out! https://t.co/iFeTodQEd6 ...
I've got issues with envs on this version. They're not working it seems.
Read more >
Uppy File Uploading - Tumblr
I had loads of constraints to deal with: browser support, server settings, variance in user tech ... const Dashboard = require('uppy/lib/plugins/Dashboard') ...
Read more >
CORS policy blocks CSS and JS from vite server using Laragon
What bothers me the most is that after doing some NPM package updates it stoped working again. Did the same, switched to different...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found