Skip to content
On this page

Free Online Conference

ViteConf - Oct 11

Get your ticket now!

Troubleshooting

See Rollup's troubleshooting guide for more information too.

If the suggestions here don't work, please try posting questions on GitHub Discussions or in the #help channel of Vite Land Discord.

CLI

Error: Cannot find module 'C:\foo\bar&baz\vite\bin\vite.js'

The path to your project folder may include &, which doesn't work with npm on Windows (npm/cmd-shim#45).

You will need to either:

  • Switch to another package manager (e.g. pnpm, yarn)
  • Remove & from the path to your project

Dev Server

Requests are stalled forever

If you are using Linux, file descriptor limits and inotify limits may be causing the issue. As Vite does not bundle most of the files, browsers may request many files which require many file descriptors, going over the limit.

To solve this:

  • Increase file descriptor limit by ulimit

    shell
    # Check current limit
    $ ulimit -Sn
    # Change limit (temporary)
    $ ulimit -Sn 10000 # You might need to change the hard limit too
    # Restart your browser
    
  • Increase the following inotify related limits by sysctl

    shell
    # Check current limits
    $ sysctl fs.inotify
    # Change limits (temporary)
    $ sudo sysctl fs.inotify.max_queued_events=16384
    $ sudo sysctl fs.inotify.max_user_instances=8192
    $ sudo sysctl fs.inotify.max_user_watches=524288
    

431 Request Header Fields Too Large

When the server / WebSocket server receives a large HTTP header, the request will be dropped and the following warning will be shown.

Server responded with status code 431. See https://vitejs.dev/guide/troubleshooting.html#_431-request-header-fields-too-large.

This is because Node.js limits request header size to mitigate CVE-2018-12121.

To avoid this, try to reduce your request header size. For example, if the cookie is long, delete it. Or you can use --max-http-header-size to change max header size.

HMR

Vite detects a file change but the HMR is not working

You may be importing a file with a different case. For example, src/foo.js exists and src/bar.js contains:

js
import './Foo.js' // should be './foo.js'

Related issue: #964

Vite does not detect a file change

If you are running Vite with WSL2, Vite cannot watch file changes in some conditions. See server.watch option.

A full reload happens instead of HMR

If HMR is not handled by Vite or a plugin, a full reload will happen.

Also if there is a dependency loop, a full reload will happen. To solve this, try removing the loop.

Build

Built file does not work because of CORS error

If the HTML file output was opened with file protocol, the scripts won't run with the following error.

Access to script at 'file:///foo/bar.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///foo/bar.js. (Reason: CORS request not http).

See Reason: CORS request not HTTP - HTTP | MDN for more information about why this happens.

You will need to access the file with http protocol. The easiest way to achieve this is to run npx vite preview.

Others

Syntax Error / Type Error happens

Vite cannot handle and does not support code that only runs on non-strict mode (sloppy mode). This is because Vite uses ESM and it is always strict mode inside ESM.

For example, you might see these errors.

[ERROR] With statements cannot be used with the "esm" output format due to strict mode

TypeError: Cannot create property 'foo' on boolean 'false'

If these code are used inside dependencies, you could use patch-package (or yarn patch or pnpm patch) for an escape hatch.

Released under the MIT License. (c7bc8e70)