Does not work with `@nrwl/react/plugins/storybook` addon
See original GitHub issueDescribe the bug
Storybook gives the error:
ModuleBuildError: Module build failed (from ./node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js):
TypeError: Cannot read properties of undefined (reading 'replace')
at Object.nextImageLoaderStub (/Users/anatoo/Workspace/xxx/xxx/node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js:7:75)
at processResult (/Users/anatoo/Workspace/xxx/xxx/node_modules/webpack/lib/NormalModule.js:758:19)
at /Users/anatoo/Workspace/xxx/xxx/node_modules/webpack/lib/NormalModule.js:860:5
at /Users/anatoo/Workspace/xxx/xxx/node_modules/loader-runner/lib/LoaderRunner.js:400:11
at /Users/anatoo/Workspace/xxx/xxx/node_modules/loader-runner/lib/LoaderRunner.js:252:18
at runSyncOrAsync (/Users/anatoo/Workspace/xxx/xxx/node_modules/loader-runner/lib/LoaderRunner.js:156:3)
at iterateNormalLoaders (/Users/anatoo/Workspace/xxx/xxx/node_modules/loader-runner/lib/LoaderRunner.js:251:2)
at /Users/anatoo/Workspace/xxx/xxx/node_modules/loader-runner/lib/LoaderRunner.js:224:4
at /Users/anatoo/Workspace/xxx/xxx/node_modules/webpack/lib/NormalModule.js:834:15
at Array.eval (eval at create (/Users/anatoo/Workspace/xxx/xxx/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)
at runCallbacks (/Users/anatoo/Workspace/xxx/xxx/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:27:15)
Your minimal, reproducible example
None
Steps to reproduce
- Add
@nrwl/react/plugins/storybookaddon to “.storybook/main.js” - Run storybook but it just fail with the above error
Expected behavior
Storybook start normally
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: macOS
storybook-addon-next version
v1.6.7
Additional context
@nrwl/react/plugin/storybook add the below webpack loader rule.
{
test: /\.(bmp|png|jpe?g|gif|webp|avif)$/,
type: 'asset',
parser: { dataUrlCondition: { maxSize: 10000 } }
}
storybook-addon-next 's configureStaticImageImport function refer generator.filename option of the rule.
const assetRule = rules?.find(
rule =>
typeof rule !== 'string' &&
rule.test instanceof RegExp &&
rule.test.test('test.jpg')
) as RuleSetRule
assetRule.test = /\.(apng|eot|otf|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/
rules?.push({
test: /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,
issuer: { not: /\.(css|scss|sass)$/ },
use: [
{
loader: require.resolve('./next-image-loader-stub'),
options: {
filename: assetRule.generator?.filename // <<----
}
}
]
})
rules?.push({
test: /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,
issuer: /\.(css|scss|sass)$/,
type: 'asset/resource',
generator: {
filename: assetRule.generator?.filename // <<----
}
})
https://github.com/RyanClementsHax/storybook-addon-next/blob/main/src/images/webpack.ts#L15-L41
As a result, the generator.filename option is undefined and the storybook is broken.
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:15
Top Results From Across the Web
Migrate to the Nrwl React Storybook Preset - Nx
The Nx Plugin for Storybook contains executors and generators for allowing your workspace to use the powerful Storybook integration testing & documenting ...
Read more >is missing from the TypeScript compilation. Please make sure ...
I've been googling for quite a while and reading through several threads, but so far nothing has been able to help me. I...
Read more >Speed up Storybook with Vite and SWC — with the help of Nx
Vite is a build tool that ensures faster load times, faster updates, ... rootMain.addons, '@nrwl/react/plugins/storybook'], webpackFinal: async (config, ...
Read more >@nrwl/storybook - npm
Nx is a next generation build system with first class monorepo support and powerful integrations. This package is a Storybook plugin for Nx....
Read more >Vite - Storybook
Storybook is a frontend workshop for building UI components and pages in ... If you're working with Svelte's Vite plugin ( vite-plugin-svelte ),...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

We are already looking into it! Thank you all for reporting!
I’ve fixed this by downgrading
@nrwl/reactto 14.7.5