Skip to content
Latchkey

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
[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

  1. Find the import named in the error.
  2. Replace it with a browser-safe API or move it to server-only code.
  3. Re-run vite build to 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
// 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.

Frequently asked questions

What causes ""Rollup failed to resolve import" (externalized)"?
Modules like path, fs, or crypto have no browser implementation, so Rollup cannot resolve them for a web bundle.
How do I fix "Rollup failed to resolve import" (externalized)?
Remove the Node-only import from browser code

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card