What the agent does
Vite 5 prints this line whenever something loads its Node API with require('vite') instead of import. The warning does not say who did it, and there are two usual suspects with different fixes. One is your own configuration: a vite.config.js in a package whose package.json has no "type": "module" is treated as CommonJS. The other is a plugin that was published as CommonJS and requires Vite itself, in which case nothing you change in your config helps. The agent's first move is to find out which, by running the build with VITE_CJS_TRACE=true, a switch that makes Vite print a stack trace under the warning. The first frame that names a file outside node_modules/vite and outside Node's own internals is the file responsible.
EugeneMeles/laravel-react-i18n is an example of the second kind, and it has an open issue reporting this warning from a Vite 5 application. The library's README tells users to write import i18n from 'laravel-react-i18n/vite' in vite.config.js. That path resolves to a root file, vite.js, which calls require('./dist/vite'). The dist/vite it loads is compiled by tsconfig.plugin.json with "module": "CommonJS", from a src/vite.ts that begins import { createLogger } from 'vite'. After compilation that import is a require, so every application using the plugin on Vite 5 gets the warning, whatever its own module settings are.
For a plugin like this, the agent adds an ES module build of the plugin entry and makes the package say which file to use for import and which for require. That means a second compiler configuration that emits ES modules for src/vite.ts and src/plugin/, and an exports map in package.json. The map is where care is needed. That package has main, module and types fields and no exports at all, and adding one closes every path it does not list. The agent therefore enumerates the entry points users already import, the package root and ./vite, gives each an import, a require and a types condition, and keeps ./package.json reachable. It leaves the CommonJS files in place so applications on older tooling keep working.
Proof comes from a consumer, not from the library's own tests. The agent packs the library with npm pack, creates a scratch Vite 5 application with an ES module config that imports the plugin from the tarball, and runs vite build with the trace switch before and after. It also loads the plugin once with require to confirm the CommonJS path still resolves, and runs the repository's npm test, which is Jest. While reading it notes two things for the maintainer without acting on them: vite appears only under devDependencies although the published plugin needs it at run time, which is what a peer dependency is for, and the check in vite.js, typeof i18n['default'] !== undefined, compares a string with a value and so is always true.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Running Vite prints \"The CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.\" Find the cause before changing anything: install dependencies, run the project's Vite command with the environment variable VITE_CJS_TRACE=true, and identify from the stack trace the first file outside node_modules/vite and Node's internals that requires Vite. Report whether it is (a) this project's own config or script, (b) code this repository publishes, such as a Vite plugin built as CommonJS, or (c) a third-party package in node_modules. For (a): make the config an ES module by the smallest change that works, either renaming it to vite.config.mjs or .mts, or adding \"type\": \"module\" to package.json; if you add the type field, find every other .js file that relies on CommonJS (require, module.exports, __dirname) and rename it to .cjs or convert it, and list each. For (b): add an ES module build of the entry that imports Vite, keep the existing CommonJS build, and add an exports map to package.json that lists every entry point users can import today (check main, module, types, the README and any root-level shim files) with import, require and types conditions, plus ./package.json. Do not remove or rename any existing published file. For (c): do not patch node_modules; report the package and version, check whether a newer release ships an ES module build, and upgrade only if tests pass. Then prove it. For (a), run the same command again with the trace variable. For (b), run npm pack, create a scratch Vite 5 app outside the repository whose ES module config imports the packed tarball, run vite build with the trace variable before and after your change, and also require() each entry point from a .cjs file to show the CommonJS path still loads. Run the test suite and the build. Do not set VITE_CJS_IGNORE_WARNING anywhere. Open a pull request with the trace, the diagnosis and both outputs.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
For an application, a pull request that renames one config file or adds one line to package.json, followed by the list of any other files that had to change extension because the package became an ES module. For a library, a pull request with a new compiler configuration, a build script entry, and the exports map. In both cases the description starts with the stack trace that identified the culprit, so the reviewer sees why this file and not another.
The description then shows the same command run twice with VITE_CJS_TRACE=true: once printing the warning and its trace, once printing neither. For a library there is a third block, the output of requiring each entry point from a .cjs file, which is the evidence that existing CommonJS users are not broken.
A reviewer of a library change should read the exports map against how people really import the package. Any deep path that users reach today and the map omits will stop resolving after release, and no build inside the repository will catch that. The agent lists the paths it found in the README, the type definitions and the root-level files, and says plainly that it cannot see private imports in other people's code. Whether the change ships as a minor or a major version is the maintainer's call.
Run it on every pull request labelled vite-upgrade
The warning arrives with the move to Vite 5, so the upgrade pull request is the moment to deal with it. Add an automation to the Project with a github trigger on pull_request.labeled, set labels to the label you use for the upgrade, and use the prompt above. When a member labels their pull request, a run starts on it and the event is added after the prompt as text.
Two limits are worth knowing. Pull requests opened by a bot do not fire GitHub triggers, so a Dependabot or Renovate bump starts nothing until a person opens or takes over the change. And the automation's max runs per hour is shared by all its triggers, so a label applied to a batch of pull requests at once queues the extra runs until the hour has room.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
Diagnosing this means running the build, and fixing a library means building a second project to consume it. The scratch application, the packed tarball and the two traced builds are setup that has nothing to do with the product and that nobody keeps around. The agent creates them in its sandbox, uses them, and leaves their output in the session record, where the trace that blames a specific file is the first thing a reviewer reads.
A sandbox also avoids false comfort from a warm machine. A developer's node_modules may hold a linked or patched copy of the plugin, or an environment variable that already hides the warning. The run starts from a clean install of exactly what the lockfile says and checks that VITE_CJS_IGNORE_WARNING is not set, so a build with no warning means the cause is gone.
Frequently asked questions
How do I find out what is requiring Vite?
Run your usual command with VITE_CJS_TRACE=true in the environment. Vite prints a stack trace beneath the warning. Skip the frames inside node_modules/vite and the node:internal ones, and the next frame names the file. If that frame is in another package under node_modules, the fix belongs to that package and not to your config.
Is adding "type": "module" to package.json safe?
It changes how Node reads every .js file in the package, so scripts that use require, module.exports or __dirname will fail until they are renamed to .cjs or converted. Renaming only the config to vite.config.mjs avoids that and is the smaller change. The agent picks the rename unless the project is already written as ES modules.
Can I just silence it with VITE_CJS_IGNORE_WARNING?
That variable hides the message and changes nothing else. It is reasonable while you wait for a third-party plugin to publish an ES module build. For your own config or your own plugin, converting the file removes the cause and takes about as long.
The warning comes from a plugin I do not maintain. What can the agent do?
It reports the package and version, checks whether a later release ships an ES module entry, and upgrades it when your tests and build pass. If no fixed release exists, it says so and links the trace, and it does not edit files under node_modules.
More Vite jobs
More jobs like this: Fix a bug from an alert
- Fix "AttributeError: The vocab attribute was removed from KeyedVector in Gensim 4.0.0" (Gensim)
- Fix "vue-loader was used without the corresponding plugin" After Upgrading to vue-loader 15 (vue-loader)
- Fix "TypeError: WebDriver.__init__() got an unexpected keyword argument 'executable_path'" (Selenium)