Storybook example is broken on Next 12.1.5
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Windows 10 - 64bit
with npm@latest
. The issue probably exists on all environments.
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
next/image
changes in 12.1.5
broke static image imports of the Storybook example.
Failed to parse src "static/media/public/nyan-cat.png" on
next/image, if using relative image it must start with a leading slash "/" or be an absolute URL (http:// or https://)
I’ve confirmed that the issue exists in 12.1.6-canary.6
.
Expected Behavior
Images rendering without an error message.
To Reproduce
npx create-next-app --example with-storybook with-storybook-app
npm run storybook
Navigate to the Nextjs Images Page
tab.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Storybook Addon Next
A no config Storybook addon that makes Next.js features just work in Storybook. ... Supported Features; Requirements; Examples; Getting Started.
Read more >0 - Stack Overflow
There's an issue with storybook and next 12.1.5, downgrade next to 12.1.4 it should work just fine.
Read more >5 Tips for integrating Next.js with Storybook - YouTube
Don't get stuck setting up Storybook in Next.js! In this video, Michael Chan (@chantastic) helps you start your Storybook and Next.js ...
Read more >How to setup Storybook with Next.js and Tailwind CSS
Run yarn storybook to start up the dev server. Then you can start adding some story, here is an example. Story example. //...
Read more >Blog - Next.js 12.1
We now also have a multi-env Docker example with support for loading different .env files based on the environment. React 18, Server Components, ......
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 FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you @RyanClementsHax !
This is how it worked for me following Ryan’s approach:
After diving deeper into the code I found the root of the issue.
The generated code mentioned above makes the following assignments:
For some reason,
__esModule: true
isn’t preserved onmodule.exports
In order for
import Image from 'next/image'
to getmodule.exports.default
instead ofmodule.exports
,__esModule: true
needs to be present onmodule.exports
.This means that the webpack runtime is treating the export from
next/image
as if it shouldn’t be treated as an esm, which is what the code that disables image optimization requires:Consequently, because we aren’t disabling image optimization, we are getting a bunch of errors as image optimization doesn’t work outside of a nextjs environment.
Therefore, my question to the maintainers is if
__esModule: true
should be set, thus meaning that this is a bug, or if this is intended behavior and we should come up with a different solution such as the code below:(The above code feels hacky so if anyone has any better approaches, I’m all ears)