Error AtlasError Documentation and Resolution

Vite config loads an ESM-only package with require

Failed to resolve "foo". This package is ESM only but it was tried to load by `require`.

Vite hit an ESM-only package from a CommonJS-style config path, so Node could not load the dependency with require.

This package is ESM only but it was tried to load by `require`configuration
Failed to resolve "foo". This package is ESM only but it was tried to load by `require`.
  • A Vite config or dependency path uses require to load an ESM-only package.
  • The Vite config file is still treated as CommonJS.
  • The surrounding package configuration does not opt the project into ESM.
  1. Convert the Vite config to ESM-compatible imports.
  2. Add "type": "module" to the nearest package.json when appropriate.
  3. Rename vite.config.js or vite.config.ts to vite.config.mjs or vite.config.mts if that better fits the project setup.
Vite: Troubleshooting
Vite This package is ESM only but it was tried to load by require | Error Atlas