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
Below document page needs to be updated for new Custom mocking method for next/image in Storybook v7.
Try overriding the next/image option
The documentation says that you can create a custom mock for next/image by writing the following:
But when I tried it, 'image' does not exist in type 'FrameworkOptions'.
An error will appear.
importtype{StorybookConfig}from'@storybook/nextjs'constconfig: StorybookConfig={framework: {name: '@storybook/nextjs',options: {// ErrorMessage on VSCode: 'image' does not exist in type 'FrameworkOptions'image: {loading: 'eager',},},},
Unresolved code that does not work with methods up to v6
As with the issue below, starting with v7, it is no longer possible to solve the problem using the previous v6 method.
After arriving at the issue below and getting a hint, I was able to solve the problem.
This content is not written in the documentation, right?
If this method suits you or there is another solution, please add appropriate documentation.
Issue: [[Bug]: Using appDirectory in preview.ts causes reactdom.preload error with Next.js framework]
importtype{StorybookConfig}from'@storybook/nextjs'importpathfrom'path'constconfig: StorybookConfig={stories: ['../stories/**/*.stories.@(tsx|jsx|mdx)'],addons: ['@storybook/addon-essentials','storycap'],framework: {name: '@storybook/nextjs',options: {},},staticDirs: ['../public'],webpackFinal: async(config)=>{// Resolve undefined with webpackFinal's config.resolve.config.resolve=config.resolve||{}// Write webpackFinal to read MockedNextImage instead of next/image.config.resolve.alias={
...(config.resolve.alias||{}),'next/image': path.resolve(__dirname,'./MockedNextImage.tsx'),}returnconfig},}exportdefaultconfig
MockedNextImage.tsx
importImage,{ImageProps}from'../node_modules/next/image'constNextImage=(props: ImageProps)=>(// It is possible to pass props to Image as shown below.<Image{...props}priority={true}loading={undefined}unoptimizedalt=""/>)exportdefaultNextImage
yuxxxie
changed the title
[Documentation]: Document page needs to be updated for new Custom mocking method for next/image in Storybook v7
[Documentation]: Page needs to be updated for new Custom mocking method for next/image in Storybook v7
Jan 2, 2024
Describe the problem
Below document page needs to be updated for new Custom mocking method for next/image in Storybook v7.
Try overriding the next/image option
The documentation says that you can create a custom mock for next/image by writing the following:
But when I tried it, 'image' does not exist in type 'FrameworkOptions'.
An error will appear.
Documentation: [Storybook for Next.js frameworks]
.storybook/main.ts
Unresolved code that does not work with methods up to v6
As with the issue below, starting with v7, it is no longer possible to solve the problem using the previous v6 method.
Issue: [next.js NextImage's broken]
.storybook/preview.ts
Solved successful code
After arriving at the issue below and getting a hint, I was able to solve the problem.
This content is not written in the documentation, right?
If this method suits you or there is another solution, please add appropriate documentation.
Issue: [[Bug]: Using appDirectory in preview.ts causes reactdom.preload error with Next.js framework]
This is also recommended in the issue below.
Issue: [Documentation]: Next.js integration page needs to be updated for new next/image handling
.storybook/main.ts
MockedNextImage.tsx
Detailed my project information
package.json
Tasks required of Storybook maintainers
1. Updates to applicable documentation
2. Add deprecated text or labels to legacy non-functional documents
[Get started with Storybook and Next.js]
3. Adding custom image mocking functionality in the Storybook framework and documenting it in an easy-to-understand manner
Additional context
No response
The text was updated successfully, but these errors were encountered: