Skip to content
Latchkey

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

The Storybook builder walked your stories, hit an import it could not resolve to a file or package, and stopped. The failing request path in the message points at the import to fix.

What this error means

The storybook build step fails with "Module not found: Error: Can't resolve './X'" (Vite/webpack), naming a file, alias, or package that the builder could not locate from the importing module.

storybook
Module not found: Error: Can't resolve './components/Button' in '/home/runner/work/app/app/src/stories'

Common causes

A case-sensitive path that only works on macOS/Windows

The import is ./Button but the file is button.tsx. A case-insensitive dev machine resolves it; the Linux CI runner does not.

A path alias the Storybook builder does not know

The app resolves @/components/... via a tsconfig or bundler alias, but .storybook uses a different builder that was never told about the alias.

How to fix it

Match the import to the real filename exactly

  1. Read the "Can't resolve" path and compare it to the file on disk, case included.
  2. Fix the import casing or the missing extension so it resolves on Linux.
  3. Re-run storybook build to confirm the module resolves.
Terminal
# case-sensitive on Linux runners
git config core.ignorecase false
grep -rn "from './components/Button'" src

Teach the Storybook builder your aliases

Extend the builder config in .storybook/main.js so aliases resolve the same way the app does.

.storybook/main.js
// .storybook/main.js
export default {
  stories: ['../src/**/*.stories.@(ts|tsx)'],
  viteFinal: async (config) => {
    config.resolve.alias['@'] = new URL('../src', import.meta.url).pathname;
    return config;
  },
};

How to prevent it

  • Keep import casing identical to filenames so Linux CI matches local runs.
  • Mirror app path aliases into the Storybook builder config.
  • Run storybook build locally before pushing, not just storybook dev.

Related guides

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