Skip to content
Latchkey

Storybook (Vite) "Rollup failed to resolve import" in CI

The Vite builder uses Rollup for the production storybook build. Rollup resolves imports more strictly than the dev server, so a dependency that is missing, externalized, or Node-only fails the build even though storybook dev worked.

What this error means

The build fails with "[vite]: Rollup failed to resolve import 'X' from '...'." and a hint to add the import to build.rollupOptions.external.

storybook
[vite]: Rollup failed to resolve import "some-pkg" from "src/stories/Widget.tsx".
This is most likely unintended because it can break your application at runtime.

Common causes

A dependency present locally but not installed in CI

Dev mode lazily loaded it from node_modules; a clean CI install lacks it, so Rollup cannot resolve the import.

A Node built-in imported into browser code

A story pulls in a Node-only module (fs, path) that has no browser build, so Rollup cannot bundle it.

How to fix it

Install or remove the unresolved import

  1. Read the "from" path to see which module pulls in the import.
  2. Install the dependency if it is legitimately needed, or remove the import.
  3. Re-run storybook build to confirm Rollup resolves it.
Terminal
npm install some-pkg
npm run build-storybook

Externalize a Node-only dependency

If the import must stay but should not be bundled for the browser, mark it external in the Vite config.

.storybook/main.ts
// .storybook/main.ts
export default {
  viteFinal: (config) => {
    config.build = config.build || {};
    config.build.rollupOptions = { external: ['fs', 'path'] };
    return config;
  },
};

How to prevent it

  • Run storybook build (not just dev) in CI to catch Rollup resolution issues.
  • Keep every imported dependency in package.json.
  • Avoid importing Node built-ins into story/component code.

Frequently asked questions

What causes ""Rollup failed to resolve import""?
Dev mode lazily loaded it from node_modules; a clean CI install lacks it, so Rollup cannot resolve the import.
How do I fix "Rollup failed to resolve import"?
Install or remove the unresolved import

Related guides

References

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