CLI
Error: Cannot find module with & in path
Error: 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
Config
This package is ESM only
When importing an ESM only package byrequire, the following error happens.
Failed to resolve “foo”. This package is ESM only but it was tried to load by require.
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/dependency.js from /path/to/vite.config.js not supported. Instead change the require of index.js in /path/to/vite.config.js to a dynamic import() which is available in all CommonJS modules.In Node.js versions 22 and below, ESM files cannot be loaded by
require by default.
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.Solution: Increase file descriptor limit
Solution: Increase file descriptor limit
Increase file descriptor limit by
ulimit:Solution: Increase inotify limits
Solution: Increase inotify limits
Increase the following inotify related limits by
sysctl:Solution: Update systemd config
Solution: Update systemd config
If the above steps don’t work, you can try adding
DefaultLimitNOFILE=65536 as an un-commented config to the following files:- /etc/systemd/system.conf
- /etc/systemd/user.conf
* - nofile 65536 to the file /etc/security/limits.conf instead of updating systemd config files.Note that these settings persist but a restart is required.Alternatively, if the server is running inside a VS Code devcontainer, the request may appear to be stalled. To fix this issue, see Dev Containers / VS Code Port Forwarding.
Network requests stop loading
When using a self-signed SSL certificate, Chrome ignores all caching directives and reloads the content. Vite relies on these caching directives. To resolve the problem use a trusted SSL cert. See: Cache problems, Chrome issuemacOS: Install trusted cert
macOS: Install trusted cert
You can install a trusted cert via the CLI with this command:Or, by importing it into the Keychain Access app and updating the trust of your cert to “Always Trust.”
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://vite.dev/guide/troubleshooting.html#_431-request-header-fields-too-large.This is because Node.js limits request header size to mitigate CVE-2018-12121.
Dev Containers / VS Code Port Forwarding
If you are using a Dev Container or port forwarding feature in VS Code, you may need to set theserver.host option to 127.0.0.1 in the config to make it work.
This is because the port forwarding feature in VS Code does not support IPv6.
See #16522 for more details.
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:
Vite does not detect a file change
If you are running Vite with WSL2, Vite cannot watch file changes in some conditions. Seeserver.watch option.
A full reload happens instead of HMR
If HMR is not handled by Vite or a plugin, a full reload will happen as it’s the only way to refresh the state. If HMR is handled but it is within a circular dependency, a full reload will also happen to recover the execution order. To solve this, try breaking the loop. You can runvite --debug hmr to log the circular dependency path if a file change triggered it.
Build
Built file does not work because of CORS error
If the HTML file output was opened withfile 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.
No such file or directory error due to case sensitivity
If you encounter errors likeENOENT: no such file or directory or Module not found, this often occurs when your project was developed on a case-insensitive filesystem (Windows / macOS) but built on a case-sensitive one (Linux). Please make sure that the imports have the correct casing.
Failed to fetch dynamically imported module
Error:TypeError: Failed to fetch dynamically imported module
This error occurs in several cases:
Version skew
Version skew
When you deploy a new version of your application, the HTML file and the JS files still reference old chunk names that were deleted in the new deployment. This happens when:
- Users have an old version of your app cached in their browser
- You deploy a new version with different chunk names (due to code changes)
- The cached HTML tries to load chunks that no longer exist
- Keep old chunks temporarily: Consider keeping the previous deployment’s chunks for a period to allow cached users to transition smoothly.
- Use a service worker: Implement a service worker that will prefetch all the assets and cache them.
- Prefetch the dynamic chunks: Note that this does not help if your HTML file is cached by the browser due to
Cache-Controlheaders. - Implement a graceful fallback: Implement error handling for dynamic imports to reload the page when chunks are missing. See Load Error Handling for more details.
Poor network conditions
Poor network conditions
This error may occur in unstable network environments. For example, when the request fails due to network errors or server downtime.Note that you cannot retry the dynamic import due to browser limitations (whatwg/html#6768).
Browser extensions blocking requests
Browser extensions blocking requests
The error may also occur if the browser extensions (like ad-blockers) are blocking that request.It might be possible to work around by selecting a different chunk name by
build.rolldownOptions.output.chunkFileNames, as these extensions often block requests based on file names (e.g. names containing ad, track).Optimized Dependencies
Outdated pre-bundled deps when linking to a local package
The hash key used to invalidate optimized dependencies depends on the package lock contents, the patches applied to dependencies, and the options in the Vite config file that affects the bundling of node modules. This means that Vite will detect when a dependency is overridden using a feature as npm overrides, and re-bundle your dependencies on the next server start. Vite won’t invalidate the dependencies when you use a feature like npm link. In case you link or unlink a dependency, you’ll need to force re-optimization on the next server start by usingvite --force. We recommend using overrides instead, which are supported now by every package manager (see also pnpm overrides and yarn resolutions).
Performance Bottlenecks
If you suffer any application performance bottlenecks resulting in slow load times, you can start the built-in Node.js inspector with your Vite dev server or when building your application to create the CPU profile:vite-profile-0.cpuprofile in the root folder, go to https://www.speedscope.app/, and upload the CPU profile using the BROWSE button to inspect the result.
You can install vite-plugin-inspect, which lets you inspect the intermediate state of Vite plugins and can also help you to identify which plugins or middlewares are the bottleneck in your applications. The plugin can be used in both dev and build modes. Check the readme file for more details.
Others
Module externalized for browser compatibility
When you use a Node.js module in the browser, Vite will output the following warning.Module “fs” has been externalized for browser compatibility. Cannot access “fs.readFile” in client code.This is because Vite does not automatically polyfill Node.js modules.
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’
Browser extensions
Some browser extensions (like ad-blockers) may prevent the Vite client from sending requests to the Vite dev server. You may see a white screen without logged errors in this case. You may also see the following error:TypeError: Failed to fetch dynamically imported moduleTry disabling extensions if you have this issue.
Cross drive links on Windows
If there’s a cross drive links in your project on Windows, Vite may not work. An example of cross drive links are:- a virtual drive linked to a folder by
substcommand - a symlink/junction to a different drive by
mklinkcommand (e.g. Yarn global cache)