添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Skip to content

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 .

CJS

Vite CJS Node API deprecated

The CJS build of Vite's Node API is deprecated and will be removed in Vite 6. See the GitHub discussion for more context. You should update your files or frameworks to import the ESM build of Vite instead.

In a basic Vite project, make sure:

  1. The vite.config.js file content is using the ESM syntax.
  2. The closest package.json file has "type": "module" , or use the .mjs / .mts extension, e.g. vite.config.mjs or vite.config.mts .

For other projects, there are a few general approaches:

  • Configure ESM as default, opt-in to CJS if needed: Add "type": "module" in the project package.json . All *.js files are now interpreted as ESM and need to use the ESM syntax. You can rename a file with the .cjs extension to keep using CJS instead.
  • Keep CJS as default, opt-in to ESM if needed: If the project package.json does not have "type": "module" , all *.js files are interpreted as CJS. You can rename a file with the .mjs extension to use ESM instead.
  • Dynamically import Vite: If you need to keep using CJS, you can dynamically import Vite using import('vite') instead. This requires your code to be written in an async context, but should still be manageable as Vite's API is mostly asynchronous.

If you're unsure where the warning is coming from, you can run your script with the VITE_CJS_TRACE=true flag to log the stack trace:

If you'd like to temporarily ignore the warning, you can run your script with the VITE_CJS_IGNORE_WARNING=true flag:

Note that postcss config files do not support ESM + TypeScript ( .mts or .ts in "type": "module" ) yet. If you have postcss configs with .ts and added "type": "module" to package.json, you'll also need to rename the postcss config to use .cts .

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

Config

This package is ESM only

When importing a ESM only package by require , 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 <=22, ESM files cannot be loaded by require by default.

While it may work using --experimental-require-module , or Node.js >22, or in other runtimes, we still recommend converting your config to ESM by either:

  • adding "type": "module" to the nearest package.json
  • renaming vite.config.js / vite.config.ts to vite.config.mjs / vite.config.mts

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

  • Increase the following inotify related limits by sysctl