Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next/Image component not working inside Storybook #18718

Closed
weyert opened this issue Nov 3, 2020 · 5 comments
Closed

next/Image component not working inside Storybook #18718

weyert opened this issue Nov 3, 2020 · 5 comments
Milestone

Comments

@weyert
Copy link

weyert commented Nov 3, 2020

Bug report

If you want to use a storybook to assist in the development of components and one of the components happens to use the new Image-component than storybook will return an error.

Describe the bug

A runtime error is thrown when trying to navigate to a story of a component using Next's Image-component:

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Clone https://github.com/weyert/next10-storybook
  2. Run npm run storybook
  3. Notice that the WidgetCard story isn't loading due to errors

Expected behavior

I would expect to be able to use the Image-component without the error being shown:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `WidgetCard `.
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `WidgetCard`.
    at createFiberFromTypeAndProps (http://192.168.1.98:6006/vendors~main.5a8c431dbe2b51c237cc.bundle.js:111604:21)
    at createFiberFromElement (http://192.168.1.98:6006/vendors~main.5a8c431dbe2b51c237cc.bundle.js:111632:15)
    at createChild (http://192.168.1.98:6006/vendors~main.5a8c431dbe2b51c237cc.bundle.js:99997:28)
    at reconcileChildrenArray (http://192.168.1.98:6006/vendors~main.5a8c431dbe2b51c237cc.bundle.js:100270:25)
    at reconcileChildFibers (http://192.168.1.98:6006/vendors~main.5a8c431dbe2b51c237cc.bundle.js:100676:14)
    at reconcileChildren (http://192.168.1.98:6006/vendors~main.5a8c431dbe2b51c237cc.bundle.js:103541:28)
    at updateHostComponent (http://192.168.1.98:6006/vendors~main.5a8c431dbe2b51c237cc.bundle.js:104183:3)
    at beginWork (http://192.168.1.98:6006/vendors~main.5a8c431dbe2b51c237cc.bundle.js:105631:14)
    at HTMLUnknownElement.callCallback (http://192.168.1.98:6006/vendors~main.5a8c431dbe2b51c237cc.bundle.js:90496:14)
    at Object.invokeGuardedCallbackDev (http://192.168.1.98:6006/vendors~main.5a8c431dbe2b51c237cc.bundle.js:90545:16)

If I remove the Image-component the story loads without errors.

I have made a repo which reproduces the problem of storybook not working as expected I am not getting the exactly same error as above but it behaves similarly by not showing the WidgetCard story at all

Screenshots

N/A

System information

  • OS: macOS
  • Browser (if applies) chrome
  • Version of Next.js: 10.0.0
  • Version of Node.js: 14.8..0

Additional context

I am using the following storybook main.js file:

const path = require('path')
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin')

module.exports = {
  stories: ['../**/*.stories.@(ts|tsx|js|jsx|mdx)'],
  addons: ['@storybook/addon-actions', '@storybook/addon-links', '@storybook/addon-viewport', '@storybook/addon-knobs'],
  webpackFinal: async (config, { configType }) => {
    // `configType` has a value of 'DEVELOPMENT' or 'PRODUCTION'
    // You can change the configuration based on that.
    // 'PRODUCTION' is used when building the static version of storybook.

    // Ensure the `paths`-defined in tsconfig.json are correctly resolved by webpack
    config.resolve.plugins = [
      new TsconfigPathsPlugin({
        configFile: path.resolve(__dirname, '../tsconfig.json'),
      }),
    ]

    // Return the altered config
    return config
  },
}
@weyert weyert added the bug Issue was opened via the bug report template. label Nov 3, 2020
@Timer Timer added this to the 10.x.x milestone Nov 3, 2020
@Timer Timer added kind: bug and removed bug Issue was opened via the bug report template. labels Nov 3, 2020
@styfle
Copy link
Member

styfle commented Nov 11, 2020

This looks like a duplicate of #18393

@styfle styfle closed this as completed Nov 11, 2020
@Timer Timer modified the milestones: 10.x.x, iteration 12 Nov 11, 2020
@weyert
Copy link
Author

weyert commented Nov 11, 2020

Hmm, duplicate indeed, but what is suggested there seems to be to use a next plugin which Vercel says shouldn't be used:

This package is still very experimental and should not be used at this point

@aippili-asp
Copy link

aippili-asp commented Nov 17, 2020

Is there any solution for this one?

@tiavina-mika

This comment has been minimized.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants