You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Storybook within a Turborepo monorepo containing a Next.js app (pressweb). The Next.js app uses a custom image loader defined via loader: 'custom' and loaderFile: './lib/imageLoader.ts' in its next.config.ts, which works correctly within the app.
I need to get this same custom loader working for next/image components within Storybook (@storybook/nextjs framework). I've reviewed the official @storybook/nextjs docs (@https://storybook.js.org/docs/get-started/frameworks/nextjs?renderer=react), but couldn't find a clear solution for custom loaders.
Configuring Storybook via the nextConfigPath option in main.ts (pointing to the app's next.config.ts) does not seem to activate the custom loader nad does not throw any errors. The custom loader function does not execute in Storybook, resulting in broken images as the raw src ID is used instead of the loader-generated URL.
exportdefaultfunctionimageLoader({ src, width, quality }: {src: stringwidth: numberquality?: number}){console.log('[imageLoader] Called with:',{ src, width, quality });// This log does NOT appear in Storybookconsturl=`https://your-image-cdn.com/r${width||''}x/q${quality||75}/${src}.webp`;console.log('[imageLoader] Returning URL:',url);returnurl;}
Storybook Main Config (apps/docs/.storybook/main.ts - Attempt with nextConfigPath):
Using nextConfigPath in main.ts to point to the Next.js app's configuration does not result in the custom image loader being used by next/image in Storybook. The console.log within the loader never fires. The component defaults to using the raw src ID, leading to broken images.
Setting unoptimized: true in preview.ts parameters works as expected (shows broken image with raw ID), confirming the issue is specifically with custom loader execution via the intended configuration.
Question: How can we correctly configure @storybook/nextjs in a Turborepo setup to use a custom next/image loader defined in a specific Next.js application package (apps/<app-name>) by referencing its next.config.ts?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'm using Storybook within a Turborepo monorepo containing a Next.js app (
pressweb
). The Next.js app uses a custom image loader defined vialoader: 'custom'
andloaderFile: './lib/imageLoader.ts'
in itsnext.config.ts
, which works correctly within the app.I need to get this same custom loader working for
next/image
components within Storybook (@storybook/nextjs
framework). I've reviewed the official@storybook/nextjs
docs (@https://storybook.js.org/docs/get-started/frameworks/nextjs?renderer=react), but couldn't find a clear solution for custom loaders.Configuring Storybook via the
nextConfigPath
option inmain.ts
(pointing to the app'snext.config.ts
) does not seem to activate the custom loader nad does not throw any errors. The custom loader function does not execute in Storybook, resulting in broken images as the rawsrc
ID is used instead of the loader-generated URL.Thanks in advance for any help.
Additional information
Environment:
@storybook/nextjs
Version: 8.6.12Relevant Configuration Snippets:
Next.js Config (
apps/<app-name>/next.config.ts
):Custom Loader (
apps/<app-name>/lib/imageLoader.ts
):Storybook Main Config (
apps/docs/.storybook/main.ts
- Attempt withnextConfigPath
):Storybook Preview Config (
apps/docs/.storybook/preview.ts
):Issue Summary:
Using
nextConfigPath
inmain.ts
to point to the Next.js app's configuration does not result in the custom image loader being used bynext/image
in Storybook. Theconsole.log
within the loader never fires. The component defaults to using the rawsrc
ID, leading to broken images.Setting
unoptimized: true
inpreview.ts
parameters works as expected (shows broken image with raw ID), confirming the issue is specifically with custom loader execution via the intended configuration.Question: How can we correctly configure
@storybook/nextjs
in a Turborepo setup to use a customnext/image
loader defined in a specific Next.js application package (apps/<app-name>
) by referencing itsnext.config.ts
?Create a reproduction
No response
Beta Was this translation helpful? Give feedback.
All reactions