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.
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
- Add the same alias to the Storybook builder config.
// .storybook/main.js (Vite builder)
viteFinal: async (config) => {
config.resolve.alias['@'] = path.resolve(__dirname, '../src');
return config;
},Install missing deps and fix the path
- Install the package, verify the file exists with exact casing.
npm install <package>
ls -la src/components/Button.tsxHow 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.