Vite "Rollup failed to resolve import ... externalized for browser compatibility" in CI
During vite build, Rollup could not resolve an import and reports it was externalized for browser compatibility. The module is a Node built-in or a package with no browser entry, so it cannot be bundled for the web.
What this error means
The build fails with "[vite]: Rollup failed to resolve import 'X' from 'src/...'. This is most likely unintended because it can break your application at runtime." and may mention externalization for browser compatibility.
[vite]: Rollup failed to resolve import "path" from "src/util.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`Common causes
A Node built-in imported in browser code
Modules like path, fs, or crypto have no browser implementation, so Rollup cannot resolve them for a web bundle.
A package without a browser-resolvable entry
A dependency exposes no browser or ESM entry that Vite can follow, so the import stays unresolved.
How to fix it
Remove the Node-only import from browser code
- Find the import named in the error.
- Replace it with a browser-safe API or move it to server-only code.
- Re-run
vite buildto confirm it resolves.
Externalize it intentionally if it belongs outside the bundle
For a library build where the host provides the module, mark it external so Rollup does not try to resolve it.
// vite.config.js
export default {
build: { rollupOptions: { external: ['path'] } },
};How to prevent it
- Keep Node built-ins out of browser-targeted code.
- Declare intentional externals in
build.rollupOptions.external. - Verify dependencies expose a browser/ESM entry before importing them.