Next.js: Image component does not work with Storybook

Created on 28 Oct 2020  路  2Comments  路  Source: vercel/next.js

Bug report

Describe the bug

using next/image component in storybook throw Error.

To Reproduce

  1. Set up with-storybook example yarn create next-app --example with-storybook with-storybook-app
  2. Create new story using next/image
    ```image.stories.js
    import Image from 'next/image'
    import React from 'react'

export default { title: 'Image' }
// image url
const url = 'https://......'

export const withNextImage = () => (

)
```

  1. Start storybook

Expected behavior

show Image without Error as plane image tag do.

Screenshots

image

System information

  • OS: macOS
  • Browser Chrome
  • Version of Next.js: 10.0.0
  • Version of Node.js: v12.16.3
bug 2 needs investigation

Most helpful comment

The import is fixed when adding @next/plugin-storybook like in PR #18367.

However, this only solves the problem for 3rd party loaders like imgix, cloudinary, etc.

For the default loader, we still need a way to expose the API at /_next/image such that it can be used from a different port.

For example, storybook is running on 6006 and next dev is running on 3000, so we need to change the src to something like http://localhost:3000/_next/image or else the images aren't loaded by the browser when visiting http://localhost:6006.

All 2 comments

The import is fixed when adding @next/plugin-storybook like in PR #18367.

However, this only solves the problem for 3rd party loaders like imgix, cloudinary, etc.

For the default loader, we still need a way to expose the API at /_next/image such that it can be used from a different port.

For example, storybook is running on 6006 and next dev is running on 3000, so we need to change the src to something like http://localhost:3000/_next/image or else the images aren't loaded by the browser when visiting http://localhost:6006.

Is there any workaround for this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robinvdvleuten picture robinvdvleuten  路  74Comments

arunoda picture arunoda  路  103Comments

baldurh picture baldurh  路  74Comments

matthewmueller picture matthewmueller  路  102Comments

dunika picture dunika  路  58Comments