ladle: Ladle breaks when next/image component is imported
I have stories for simple components that work fine. But once I click on a story for a component that uses the next/image component, nothing renders and ladle is broken until reload. Once I clock on a story with next/image the following error occurs in the console:
react.development.js:1309 Uncaught ReferenceError: process is not defined
at node_modules/next/dist/client/normalize-trailing-slash.js (normalize-trailing-slash.ts:12:43)
at __require (chunk-MYIE5J7A.js?v=88870cd9:25:50)
at node_modules/next/dist/shared/lib/router/router.js (router.ts:13:50)
at __require (chunk-MYIE5J7A.js?v=88870cd9:25:50)
at node_modules/next/dist/client/link.js (link.tsx:11:37)
at __require (chunk-MYIE5J7A.js?v=88870cd9:25:50)
at node_modules/next/link.js (link.js:1:18)
at __require (chunk-MYIE5J7A.js?v=88870cd9:25:50)
at dep:next_link:1:16
node_modules/next/dist/client/normalize-trailing-slash.js @ normalize-trailing-slash.ts:12
__require @ chunk-MYIE5J7A.js?v=88870cd9:25
node_modules/next/dist/shared/lib/router/router.js @ router.ts:13
__require @ chunk-MYIE5J7A.js?v=88870cd9:25
node_modules/next/dist/client/link.js @ link.tsx:11
__require @ chunk-MYIE5J7A.js?v=88870cd9:25
node_modules/next/link.js @ link.js:1
__require @ chunk-MYIE5J7A.js?v=88870cd9:25
(anonymous) @ dep:next_link:1
react_devtools_backend.js:3973 The above error occurred in one of your React components:
at Lazy
at Provider (http://localhost:61000/generated/generated-list.tsx:114:28)
at Suspense
at ErrorBoundary (http://localhost:61000/src/error-boundary.tsx:4:5)
at Story (http://localhost:61000/src/story.tsx:11:18)
at main
at App (http://localhost:61000/src/app.tsx:24:41)
React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary.
Here is a screenshot for better readability:
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 15 (2 by maintainers)
@bonesoul
You have to create
vite.config.jsorvite.config.tsin your root folder, not.laddle(this was what I did wrong at least) with the following:This resolves the
process is not definedfor me, but I still have this issue with imagesI found another solution which uses vite aliases to append the
unoptimizedprop tonext/image:vite.config.ts:
.ladle/UnoptimizedImage.tsx:
For a more detailed description, please have a look at https://sdorra.dev/posts/2023-01-18-ladle-next-image#nextimage
Nice workaround, thanks @jeremytenjo!
I think long term an option like Storybook’s workaround would be preferred to keep mock/ladle props out of the bundle
Would
.ladle/components.tsxbe the best place for this? 🤔