Skip to content
Latchkey

Storybook "Module not found: Error: Can't resolve" in .storybook in CI

The Storybook builder (Webpack or Vite) tried to bundle the preview and could not resolve an import from .storybook/preview or main. The path is wrong, the file is missing, or a package is uninstalled.

What this error means

The build fails with "Module not found: Error: Can't resolve '../src/styles.css' in '/home/runner/work/app/app/.storybook'".

storybook
ERROR in ./.storybook/preview.js
Module not found: Error: Can't resolve '../src/global.css' in
'/home/runner/work/app/app/.storybook'

Common causes

A relative import path is wrong from .storybook

Paths in preview and main are relative to the .storybook folder, not the project root, so a path that looks right can resolve to nothing on the runner.

The imported file or package is not committed or installed

A stylesheet, decorator, or helper imported by the config is gitignored or a package is uninstalled, so resolution fails in a clean CI checkout.

How to fix it

Fix the path relative to .storybook

  1. Check the directory in the error: it is the .storybook folder.
  2. Adjust the relative import so it resolves from there.
  3. Re-run the build to confirm the module resolves.
.storybook/preview.js
// .storybook/preview.js  (relative to .storybook/)
import '../src/global.css';

Ensure the import target exists in CI

Confirm the imported file is committed (not gitignored) and any imported package is in devDependencies.

How to prevent it

  • Remember config paths are relative to .storybook, not the repo root.
  • Commit every file the Storybook config imports.
  • Run the Storybook build in CI so resolution errors surface on PRs.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →