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.
[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
- Read the "from" path to see which module pulls in the import.
- Install the dependency if it is legitimately needed, or remove the import.
- Re-run
storybook buildto confirm Rollup resolves it.
npm install some-pkg
npm run build-storybookExternalize 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
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.