Unable to Mock Modules in Storybook #28525
-
SummaryDescribe the bugI’ve been attempting to mock modules in one of my projects following this guide, but I can’t get it to work. The mock is never displayed inside Storybook. ReproductionIn stackblitz I can't reproduce the problem, all it works fine here The stories is MapLegend.stories.tsx It works when the text below is displayed : I have a complicated stack that I can't reproduce in stackblitz
I have tried with node 20.15.0, nx 19.4.0 and storybook 8.2.0-alpha.10 but it doesn't work. In the package.json I have this :
how storybook know that the code is run in storybook, in other word how and who set the condition storybook ? We have a ./storybook/main.ts complicated, when I use the main.ts comes from my example it works. See below my devDependencies.
Additional informationNo response Create a reproduction |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Which builder are you using? Could you share your For webpack you can set the condition like this: For Vite: |
Beta Was this translation helpful? Give feedback.
-
I use vite js. main.ts :
|
Beta Was this translation helpful? Give feedback.
-
Thank you very much, it works fine. |
Beta Was this translation helpful? Give feedback.
Right so you have to set the
resolve.conditions = ['storybook']
as described here:https://vitejs.dev/config/shared-options#resolve-conditions