Skip to content
Latchkey

Storybook "Module not found" - Fix in CI

Storybook's builder walked a story import and could not resolve it. The package is missing, an alias is not mirrored into Storybook, or the path/case is wrong.

What this error means

The build reports Module not found: Error: Can't resolve '<module>' from a story or a component it imports.

webpack
ModuleNotFoundError: Module not found:
Error: Can't resolve '@/components/Button' in '/app/src/stories'

Common causes

Alias not configured for Storybook

A @/ alias works in the app build but is not mirrored into .storybook/main viteFinal/webpackFinal.

Missing dependency or wrong path

The imported package is not installed, or the relative path/case is wrong on the Linux runner.

How to fix it

Mirror app aliases into Storybook

  1. Add the same alias to the Storybook builder config.
.storybook/main.js
// .storybook/main.js (Vite builder)
viteFinal: async (config) => {
  config.resolve.alias['@'] = path.resolve(__dirname, '../src');
  return config;
},

Install missing deps and fix the path

  1. Install the package, verify the file exists with exact casing.
Terminal
npm install <package>
ls -la src/components/Button.tsx

How to prevent it

  • Keep Storybook builder aliases in sync with the app build and tsconfig paths.
  • Run Storybook builds in CI to catch resolution drift.

Related guides

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