image icon indicating copy to clipboard operation
image copied to clipboard

NuxtImg Component Not Rendering in Storybook

Open Kingo4luv opened this issue 1 year ago • 3 comments

I am attempting to integrate Storybook with my Nuxt 3 application. While most components render perfectly, I'm facing issues specifically with the NuxtImg component. It works as expected within the Nuxt app, but throws an error when visualized in Storybook.

Error Message:

[Vue warn]: Component is missing template or render function. 
at <NuxtImg class="w-full h-full object-cover object-center null" alt="Another Night Somewhere in the Universe" provider="imgix" ... >
Screenshot 2023-10-02 at 12 47 02

Component Code:

<template>
    <nuxt-img
        class="w-full h-full object-cover object-center"
        :class="`${rounded[radius]} ${imgClass}`"
        :alt="alternateText"
        provider="imgix"
        :src="file.filename"
        :sizes="size"
        loading="lazy"
        :preload="preload"
        :preset="preset"
        @load="$emit('image-loaded')"
    />
</template>

Expected Behavior: The NuxtImg component should render without issues in Storybook just as it does within the Nuxt application.

Actual Behavior: The component throws an error and doesn't display as expected.

Steps to Reproduce:

Set up a Nuxt 3 project. Integrate Storybook. Create a component utilizing NuxtImg. Attempt to visualize the component in Storybook. Environment:

Nuxt version: v3.7.3 Nuxt Image verson: v1.0.0-rc.2 Nuxt Storybook version: v7.0.0 Node version: v18.16.0 Browser: Chrome, Firefox, Safari OS: MacOS, Windows

Additional Notes: I've followed the recommended configurations for both Nuxt and Storybook. Other components without NuxtImg seem to render fine in Storybook. Any assistance on this would be greatly appreciated!

Kingo4luv avatar Oct 02 '23 11:10 Kingo4luv

that happens to me too

perezguedesmaikel avatar Dec 26 '23 11:12 perezguedesmaikel

Having the same issue

yuuzora avatar May 03 '24 13:05 yuuzora

Take a look here, I mocked the component to show a simple html image

https://github.com/Archetipo95/my-nuxt-starter/blob/main/.storybook/mocks/NuxtImage.ts

Archetipo95 avatar May 30 '24 15:05 Archetipo95