Code Monkey home page Code Monkey logo

storybook-addon-next's Introduction

Storybook Addon Next

⚠️ DEPRECATED ⚠️

This addon has been deprecated in favor of @storybook/nextjs which is the Storybook official addon for supporting Next.js features in Storybook. It supports everything storybook-addon-next does and much more! I even worked on developing this with them so you should be in good hands.

Consult the migration docs for details on how to migrate.


😱 No config support for Next.js: Tired of writing and debugging webpack config? What Next.js supports out of the box, this addon makes possible in Storybook

current version Commitizen friendly semantic-release semantic-release: angular

Table of Contents

Supported Features

👉 Next.js's Image Component (partial support)

👉 Next.js Routing

👉 Sass/Scss

👉 Css/Sass/Scss Modules

👉 Styled JSX

👉 Postcss

👉 Absolute Imports

👉 Runtime Config

👉 Custom Webpack Config

👉 Typescript

Requirements

  • Next.js >= 9.x
  • Storybook >= 6.x
    • Storybook webpack 5 builder
      • Intro
      • Installation guide
      • It's not that this plugin can't support the webpack 4 builder, it's just that there hasn't been much of a need to and this is what Storybook recommends for nextjs apps. If you feel that you have a good use case, feel free to open up an issue.
  • Your Next.js config file uses the .js extension and not the .mjs extension (i.e. next.config.js not next.config.mjs)

Examples

To run any example, first build the addon by running yarn build in the root of this repo.

Getting Started

Installation

Install storybook-addon-next using yarn:

yarn add --dev storybook-addon-next

Or npm:

npm install --save-dev storybook-addon-next

Register the Addon in main.js

// .storybook/main.js

module.exports = {
  // other config ommited for brevity
  addons: [
    // ...
    'storybook-addon-next'
    // ...
  ]
}

Partay

🥳🎉 Thats it! The supported features should work out of the box.

See Documentation for more details on how the supported features work in this addon.

If something doesn't work as you would expect, feel free to open up an issue.

Documentation

Options

This addon can be passed an options object for addional configuration if needed.

For example:

// .storybook/main.js
const path = require('path')

module.exports = {
  // other config ommited for brevity
  addons: [
    // ...
    {
      name: 'storybook-addon-next',
      options: {
        nextConfigPath: path.resolve(__dirname, '../next.config.js')
      }
    }
    // ...
  ]
}
  • nextConfigPath: The absolute path to the next.config.js

Next.js's Image Component (partial support)

next/image is notoriously difficult to get working with storybook. This addon allows you to use Next.js's Image component with no configuration!

Because the image component has features, like image optimization, configured by options that require the Next.js config file to be read and processed by the framework and there is no public function exposed by Next.js to resolve and those options, it is not possible to support those features stably.

If you want to see this better supported, feel free to contribute to the discussion on Next.js's side or the discussion on our side

Local Images

Local images work just fine with this addon! Keep in mind that this feature was only added in Next.js v11.

import Image from 'next/image'
import profilePic from '../public/me.png'

function Home() {
  return (
    <>
      <h1>My Homepage</h1>
      <Image
        src={profilePic}
        alt="Picture of the author"
        // width={500} automatically provided
        // height={500} automatically provided
        // blurDataURL="../public/me.png" set to equal the image itself (for this addon)
        // placeholder="blur" // Optional blur-up while loading
      />
      <p>Welcome to my homepage!</p>
    </>
  )
}

Remote Images

Remote images also work just fine!

import Image from 'next/image'

export default function Home() {
  return (
    <>
      <h1>My Homepage</h1>
      <Image
        src="/me.png"
        alt="Picture of the author"
        width={500}
        height={500}
      />
      <p>Welcome to my homepage!</p>
    </>
  )
}

Optimization

All Next.js Images are automatically unoptimized for you.

If placeholder="blur" is used, the blurDataURL used is the src of the image (thus effectively disabling the placeholder).

See this issue for more discussion on how Next.js Images are handled for Storybook.

AVIF

This format is not supported by this addon yet. Feel free to open up an issue if this is something you want to see.

Next.js Routing

This solution is heavily based on storybook-addon-next-router so a big thanks to lifeiscontent for providing a good solution that this addon could work off of.

Next.js's router is automatically stubbed for you so that when the router is interacted with, all of its interactions are automatically logged to the Storybook actions tab if you have the actions addon.

Overriding defaults

Per-story overrides can be done by adding a nextRouter property onto the story parameters. The addon will shallowly merge whatever you put here into the router.

import SomeComponentThatUsesTheRouter from "./SomeComponentThatUsesTheRouter";

export default {
  title: "My Story",
};

// if you have the actions addon
// you can click the links and see the route change events there
export const Example = () => <SomeComponentThatUsesTheRouter />;

Example.parameters: {
  nextRouter: {
    path: "/profile/[id]",
    asPath: "/profile/ryanclementshax",
    query: {
      id: "ryanclementshax"
    }
  }
}

See this example for a reference.

Global Defaults

Global defaults can be set in preview.js and will be shallowly merged with the default router.

export const parameters = {
  nextRouter: {
    path: '/some-default-path',
    asPath: '/some-default-path',
    query: {}
  }
}

See this example for a reference.

Default Router

The default values on the stubbed router are as follows (see globals for more details on how globals work)

const defaultRouter = {
  locale: context?.globals?.locale,
  route: '/',
  pathname: '/',
  query: {},
  asPath: '/',
  push(...args: unknown[]) {
    action('nextRouter.push')(...args)
    return Promise.resolve(true)
  },
  replace(...args: unknown[]) {
    action('nextRouter.replace')(...args)
    return Promise.resolve(true)
  },
  reload(...args: unknown[]) {
    action('nextRouter.reload')(...args)
  },
  back(...args: unknown[]) {
    action('nextRouter.back')(...args)
  },
  prefetch(...args: unknown[]) {
    action('nextRouter.prefetch')(...args)
    return Promise.resolve()
  },
  beforePopState(...args: unknown[]) {
    action('nextRouter.beforePopState')(...args)
  },
  events: {
    on(...args: unknown[]) {
      action('nextRouter.events.on')(...args)
    },
    off(...args: unknown[]) {
      action('nextRouter.events.off')(...args)
    },
    emit(...args: unknown[]) {
      action('nextRouter.events.emit')(...args)
    }
  },
  isFallback: false
}

Actions Integration Caveats

If you override a function, you lose the automatic action tab integration and have to build it out yourself.

export const parameters = {
  nextRouter: {
    push() {
      // we lose the default implementation that logs the action into the action tab
    }
  }
}

Doing this yourself looks something like this (make sure you install the @storybook/addon-actions package):

import { action } from '@storybook/addon-actions'

export const parameters = {
  nextRouter: {
    push(...args) {
      // custom logic can go here
      // this logs to the actions tab
      action('nextRouter.push')(...args)
      // return whatever you want here
      return Promise.resolve(true)
    }
  }
}

Sass/Scss

Global sass/scss stylesheets are supported without any additional configuration as well. Just import them into preview.js

import '../styles/globals.scss'

This will automatically include any of your custom sass configurations in your next.config.js file.

Right now only the .js extension of the Next.js config is supported, not .mjs. See next.config.js for more details.

const path = require('path')

module.exports = {
  // any options here are included in sass compilation for your stories
  sassOptions: {
    includePaths: [path.join(__dirname, 'styles')]
  }
}

Css/Sass/Scss Modules

Next.js supports css modules out of the box so this addon supports it too.

// this import works just fine in Storybook now
import styles from './Button.module.css'
// sass/scss is also supported
// import styles from './Button.module.scss'
// import styles from './Button.module.sass'

export function Button() {
  return (
    <button type="button" className={styles.error}>
      Destroy
    </button>
  )
}

Styled JSX

The built in CSS in JS solution for Next.js is styled-jsx, and this addon supports that out of the box too, zero config.

// This works just fine in Storybook with this addon
function HelloWorld() {
  return (
    <div>
      Hello world
      <p>scoped!</p>
      <style jsx>{`
        p {
          color: blue;
        }
        div {
          background: red;
        }
        @media (max-width: 600px) {
          div {
            background: blue;
          }
        }
      `}</style>
      <style global jsx>{`
        body {
          background: black;
        }
      `}</style>
    </div>
  )
}

export default HelloWorld

You can use your own babel config too. This is an example of how you can customize styled-jsx.

// .babelrc or whatever config file you use
{
  "presets": [
    [
      "next/babel",
      {
        "styled-jsx": {
          "plugins": ["@styled-jsx/plugin-sass"]
        }
      }
    ]
  ]
}

If you use a monorepo, you may need to add the babel config yourself to your storybook project. Just add a babel config to your storybook project with the following contents to get started.

{
  "presets": ["next/babel"]
}

Postcss

Next.js lets you customize postcss config. Thus this addon will automatically handle your postcss config for you.

This allows for cool things like zero config tailwindcss! See the with-tailwindcss example for reference! Its a clone of Next.js's tailwindcss example set up with storybook and this addon.

Absolute Imports

Goodbye ../! Absolute imports from the root directory work just fine with this addon.

// All good!
import Button from 'components/button'
// Also good!
import styles from 'styles/HomePage.module.css'

export default function HomePage() {
  return (
    <>
      <h1 className={styles.title}>Hello World</h1>
      <Button />
    </>
  )
}
// preview.js

// Also ok in preview.js!
import 'styles/globals.scss'

// ...

Runtime Config

Next.js allows for Runtime Configuration which lets you import a handy getConfig function to get certain configuration defined in your next.config.js file at runtime.

In the context of Storybook with this addon, you can expect Next.js's Runtime Configuration feature to work just fine.

Note, because Storybook doesn't server render your components, your components will only see what they normally see on the client side (i.e. they won't see serverRuntimeConfig but will see publicRuntimeConfig).

For example, consider the following Next.js config:

// next.config.js
module.exports = {
  serverRuntimeConfig: {
    mySecret: 'secret',
    secondSecret: process.env.SECOND_SECRET // Pass through env variables
  },
  publicRuntimeConfig: {
    staticFolder: '/static'
  }
}

Calls to getConfig would return the following object when called within Storybook:

{
  "serverRuntimeConfig": {},
  "publicRuntimeConfig": {
    "staticFolder": "/static"
  }
}

Custom Webpack Config

Next.js comes with a lot of things for free out of the box like sass support, but sometimes we add custom webpack config modifications to Next.js. This addon takes care of most of the webpack modifications you would want to add. If Next.js supports a feature out of the box, then this addon will make that feature work out of the box in Storybook. If Next.js doesn't support something out of the box, but makes it easy to configure, then this addon will do the same for that thing for Storybook. If you find something that you still need to configure webpack to get a Next.js feature to work in Storybook after adding this addon, this is likely a bug and please feel free to open up an issue.

Any webpack modifications desired for Storybook should be made in .storybook/main.js according to Storybook's docs.

Note: Not all webpack modifications are copy/paste-able between next.config.js and .storybook/main.js. It is recommended to do your reasearch on how to properly make your modifcation to Storybook's webpack config and on how webpack works.

Please feel free to contribute an example to help out the community.

Below is an example of how to add svgr support to Storybook with this addon. The full example can be found here.

// .storybook/main.js
module.exports = {
  // other config omitted for brevity
  webpackFinal: async config => {
    // this modifies the existing image rule to exclude .svg files
    // since we want to handle those files with @svgr/webpack
    const imageRule = config.module.rules.find(rule => rule.test.test('.svg'))
    imageRule.exclude = /\.svg$/

    // configure .svg files to be loaded with @svgr/webpack
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack']
    })

    return config
  }
}

Typescript

Storybook handles most Typescript configurations, but this addon adds additional support for Next.js's support for Absolute Imports and Module path aliases. In short, it takes into account your tsconfig.json's baseUrl and paths. Thus, a tsconfig.json like the one below would work out of the box.

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/components/*": ["components/*"]
    }
  }
}

next.config.js

ESM

Right now the only supported config format for Next.js that this plugin supports is the commonjs version of the config (i.e. next.config.js). This is mostly because I haven't figured out how to require a .mjs file from a storybook addon (which is bound to commonjs modules as far as I know right now). If you are able to help, I'd love it if you could contribute to this discussion to get support for the .mjs version if such support is even possible.

Notes for Yarn v2 and v3 users

If you're using Yarn v2 or v3, you may run into issues where Storybook can't resolve style-loader or css-loader. For example, you might get errors like:

Module not found: Error: Can't resolve 'css-loader'
Module not found: Error: Can't resolve 'style-loader'

This is because those versions of Yarn have different package resolution rules than Yarn v1.x. If this is the case for you, just install the package directly.

FAQ

Statically imported images won't load

Make sure you are treating image imports the same way you treat them when using next image in normal development.

Before storybook-addon-next, image imports just imported the raw path to the image (e.g. 'static/media/stories/assets/plugin.svg'). When using storybook-addon-next image imports work the "Next.js way" meaning that we now get an object when we import an image. For example:

{
  "src": "static/media/stories/assets/plugin.svg",
  "height": 48,
  "width": 48,
  "blurDataURL": "static/media/stories/assets/plugin.svg"
}

Therefore, if something in storybook isn't showing the image properly, make sure you expect the object to be returned from an import instead of just the asset path.

See local images for more detail on how Next.js treats static image imports.

This addon breaks when the .mjs extension for the next config is used

Right now using next.config.mjs isn't supported by this addon. See next.config.js for more details. Right now, it is required for you to use the .js extension instead. Feel free to help out on this discussion to get this supported.

Module not found: Error: Can't resolve [package name]

You might get this if you're using Yarn v2 or v3. See Notes for Yarn v2 and v3 users for more details.

Similar Projects

Want to suggest additional features?

I'm open to discussion. Feel free to open up an issue.

Didn't find what you were looking for?

Was this documentation insufficient for you?

Was it confusing?

Was it ... dare I say ... inaccurate?

If any of the above describes your feelings of this documentation. Feel free to open up an issue.

storybook-addon-next's People

Contributors

anatoo avatar andykenward avatar dependabot[bot] avatar devrnt avatar markky21 avatar partounian avatar ryanclementshax avatar tubbo avatar volkyeth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

storybook-addon-next's Issues

Use next-router addon instead of blatantly copy and pasting it

I've spent a lot of time with the next/storybook community making sure I've built something that works for them. I'd appreciate it if you could use my addon internally rather than just copy/pasting it.

It would also limit the scope of bugs for you and allow us to collaborate.

What do you think?

Object.defineProperty(NextImage, '__esModule', descriptor) is no more needed from [email protected]

Describe the bug

Storybook will throw an error TypeError: Cannot redefine property: __esModule at this line with using [email protected] or later.

Your minimal, reproducible example

none

Steps to reproduce

  1. Use next version 12.1.7-canary.7 or later
  2. run storybook
  3. It gives the above error

Expected behavior

Working Storybook

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Ubuntu 18.04.5
  • Browser: Chrome 102.0.5005.63
  • Node: v16.14.2
  • Relevant packages:
    • next: ~12.1.7-canary.7

storybook-addon-next version

v1.6.6

Additional context

I did some digging and found that the default import of next/image has been fixed by this PR.

The built code looks like following, so you need not to redefine __esModule property on next-image-stub.tsx.

if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
  Object.defineProperty(exports.default, '__esModule', { value: true });
  Object.assign(exports.default, exports);
  module.exports = exports.default;
}

Related issues

I'm trying to use the addon with storybook and react, but can't build storybook once I installed the addon

Describe the bug

I had a React project and tried to use the addon-next to work properly with Sass, since in my researches it helps with some problems that i was facing when using just the Storybook default config for Sass. But, when I installed sddon-next and tried to build my project, I got an error.

Your minimal, reproducible example

Default config from docs

Steps to reproduce

  1. Just reproduce the steps on the docs. yarn add --dev storybook-addon-next, added 'storybook-addon-next' to my 'main.js' and then yarn build-storybook

Expected behavior

I expected to build storybook correctly

How often does this bug happen?

Every time

Screenshots or Videos

image
image

Platform

  • OS: Ubuntu

storybook-addon-next version

1.6.7

Additional context

No response

Currently not working when using src directory

Describe the bug

Currently does not work when using the the src directory feature - https://nextjs.org/docs/advanced-features/src-directory.

Your minimal, reproducible example

https://github.com/scpaye506/nextjs-storybook-addon-src-bug

Steps to reproduce

  1. pull down repo
  2. npm install
  3. npm run storybook

Expected behavior

As a user, I expected storybook to run when using a src directory, but got the below errors:

ModuleNotFoundError: Module not found: Error: Can't resolve '../styles/globals.css'

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Mac

storybook-addon-next version

v1.4.4

Additional context

No response

Next 12.2 newNextLinkBehavior support

Describe the bug

Next.js 12.2 support new link behavior.

From https://nextjs.org/blog/next-12-2#other-improvements

next/link no longer requires manually adding as a child. You can now opt into this behavior in a backward-compatible way.

vercel/next.js#36436

I added the newNextLinkBehavior flag in my next config in next.config.js

{
  experimental: {
    newNextLinkBehavior: true,
  }
}

but when I use storybook with the new link behavior it seems to not understand it.

I get

Multiple children were passed to <Link> with `href` of `/` but only one child is supported https://nextjs.org/docs/messages/link-multiple-children 

error although in my app this resolves well.

Your minimal, reproducible example

nextjs example with-storybook-app

Steps to reproduce

  1. Add
{
  experimental: {
    newNextLinkBehavior: true,
  }
}

to next.config.js.
2. Create a component with multiple children inside Link like

import Link from "next/link";
export function MenuItem() {
  return (
    <Link href="/" >
      <div/>
      <div/>
    </Link>
  );
}
  1. Use this component in storybook story
 import { ComponentMeta, ComponentStory } from "@storybook/react";
import { MenuItem } from "./MenuItem";

export default {
  component: MenuItem,
} as ComponentMeta<typeof MenuItem>;

const Template: ComponentStory<typeof MenuItem> = (args) => (
  <MenuItem {...args} />
);

export const Regular = Template.bind({});

Expected behavior

No error will occur and the new link behavior will be supported

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

MacOS Monterey 12.4
Chrome Version 103.0.5060.114 (Official Build) (arm64)

storybook-addon-next version

^1.6.7

Additional context

No response

storybook-addon-next does not work with tailwindcss 3.

Describe the bug

  1. tailwindcss3 works well when using @storybook/addon-postcss
    (because tailwindcss3. needs postcss 8+. but storybook does not support postcss 8+.)
const path = require('path');

module.exports = {
  stories: [
    '../stories/**/*.stories.mdx',
    '../stories/**/*.stories.@(js|jsx|ts|tsx)',
  ],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/addon-interactions',
    {
      name: '@storybook/addon-postcss',
      options: {
        postcssLoaderOptions: {
          implementation: require('postcss'),
        },
      },
    },
  ],
  framework: '@storybook/react',
  core: {
    builder: '@storybook/builder-webpack5',
  },
  webpackFinal: async (config) => {
    config.resolve.modules = [path.resolve(__dirname, '..'), 'node_modules'];

    return config;
  },
  staticDirs: ['../public'],
};
  1. but, storybook-addon-next does not work with postcss 8+. :(. please help.
const path = require('path');

module.exports = {
  stories: [
    '../stories/**/*.stories.mdx',
    '../stories/**/*.stories.@(js|jsx|ts|tsx)',
  ],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/addon-interactions',
    'storybook-addon-next',
    {
      name: '@storybook/addon-postcss',
      options: {
        postcssLoaderOptions: {
          implementation: require('postcss'),
        },
      },
    },
  ],
  framework: '@storybook/react',
  core: {
    builder: '@storybook/builder-webpack5',
  },
  webpackFinal: async (config) => {
    config.resolve.modules = [path.resolve(__dirname, '..'), 'node_modules'];

    return config;
  },
  staticDirs: ['../public'],
};

It occurs this error message.
Error: PostCSS plugin tailwindcss requires PostCSS 8.

Your minimal, reproducible example

https://github.com/kyujonglee/storybook-nextjs-tailwindcss

Steps to reproduce

  1. npx create-next-app@lasest --typescript
  2. npx storybook init
  3. install @storybook/addon-postcss and tailwindcss postcss autoprefixer.

Expected behavior

storybook
nextjs
tailwindcss3

work together.

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

  • OS: macOS
  • browser: Chrome

storybook-addon-next version

v1.6.4

Additional context

No response

CSS @import throws error

Describe the bug

When using CSS @import in a .css the below error is thrown.

ModuleBuildError: Module build failed (from ./node_modules/css-loader/dist/cjs.js):
TypeError: url.startsWith is not a function

Your minimal, reproducible example

https://github.com/andykenward/storybook-addon-next/commit/4a67992f3aa3e809944b38eb961e02892bee48a3

Steps to reproduce

  1. Add a your-file.css file to styles folder. Perhaps with some css in the file.
  2. Add @import './your-file.css' into styles/global.css.
  3. Try to run storybook yarn storybook.

You should get an error and crash.

Expected behavior

To support @import in .css files.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • MacOS 12.1
  • Node 14.18.2 & 16.13.0

storybook-addon-next version

1.4.1

Additional context

This does not happen in version 1.4.0.

CSS styles are missing in the result bundle

Describe the bug

Styles, that I import in preview.js are ignored in the result bundle without any issue in the console. Storybook stories are unstyled.
To reproduce the issue, try to run storybook in both development/production mode from your example in the repo
https://github.com/RyanClementsHax/storybook-addon-next/tree/main/examples/with-tailwindcss

I'm facing same issue in real project also.

Your minimal, reproducible example

https://github.com/RyanClementsHax/storybook-addon-next/tree/main/examples/with-tailwindcss

Steps to reproduce

To reproduce the issue, try to run storybook in both development/production mode from your example in the repo
https://github.com/RyanClementsHax/storybook-addon-next/tree/main/examples/with-tailwindcss

Expected behavior

Weback pick up the styles that you import in preview.js file.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

OS: macOS
Node: 0.39.1

storybook-addon-next version

1.6.6

Additional context

No response

CSS import not working in .storybook/preview.js after adding 'storybook-addon-next',

Describe the bug

Hi I am using Storybook 6.4.22 with Next 12.1.5 and Typescript 4.4.2(Node 16). I have to add global fonts for our stories. I tried adding that in preview.js and it worked fine initially. I had to use 'storybook-addon-next' because some of our components are pulling info out of configs(getConfig()?.serverRuntimeConfig?.config). After adding the addon my global import of fonts has stopped working.
Thanks in advance for your help.

storybook/Main.js

module.exports = {
stories: ['../src//*.stories.mdx', '../src//*.stories.@(js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'storybook-addon-tags',
'storybook-addon-next',
],
framework: '@storybook/react',
core: {
builder: '@storybook/builder-webpack5',
},
}

storybook/preview.js

import '@UI/palette/build/web/fonts/fonts-cdn.css' //css import
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
}

Your minimal, reproducible example

explained above

Steps to reproduce

explained above

Expected behavior

none

How often does this bug happen?

No response

Screenshots or Videos

none

Platform

-OS[MAC OS]

storybook-addon-next version

"^1.6.2"

Additional context

No response

Incopatibility with @storybook/builder-vite

Describe the bug

Using storybook-addon-next in combination with builder-vite produces an error once storybook server started.

Reproduce repo link.
I've added instruction to start.

All packages have latest versions.

A warning message:

Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: 

Error message is somehow related with next-image-stub.js:

Uncaught TypeError: Invalid Version: undefined
    at new SemVer (semver.js:19:13)
    at compare (compare.js:3:3)
    at Object.gt (gt.js:2:29)
    at node_modules/storybook-addon-next/dist/images/next-image-stub.js (next-image-stub.js:7:22)
    at __require2 (chunk-S5KM4IGW.js?v=7ad206d8:18:50)
    at node_modules/storybook-addon-next/dist/preview.js (preview.js:7:1)
    at __require2 (chunk-S5KM4IGW.js?v=7ad206d8:18:50)
    at dep:storybook-addon-next_dist_preview__js:1:16

Your minimal, reproducible example

Branch bug:
https://github.com/dvakatsiienko/next-vite-storybook/tree/bug

Steps to reproduce

  1. Clone repository
  2. yarn
  3. yarn storybook:start
  4. Once Vite bundled, go to http://localhost:6006/
  5. Inspect an error in console

Expected behavior

As a user I expect a correctly rendered page.

How often does this bug happen?

Every time

Screenshots or Videos

Screen.Recording.2022-09-23.at.06.36.02.PM.mp4

Platform

  • OS MacOS
  • All packages latest versions

storybook-addon-next version

1.6.9

Additional context

No response

Styled JSX error

Describe the bug

When a mount a <style jsx global> element I got an error:

ReferenceError: _JSXStyle is not defined
    at GlobalStyles (http://localhost:3000/main.iframe.bundle.js:68147:34)
    at renderWithHooks (http://localhost:3000/vendors-node_modules_ebay_nice-modal-react_lib_esm_index_js-node_modules_gogaille_sanity-imag-919ca0.iframe.bundle.js:141207:18)
    at mountIndeterminateComponent (http://localhost:3000/vendors-node_modules_ebay_nice-modal-react_lib_esm_index_js-node_modules_gogaille_sanity-imag-919ca0.iframe.bundle.js:144033:13)
    at beginWork (http://localhost:3000/vendors-node_modules_ebay_nice-modal-react_lib_esm_index_js-node_modules_gogaille_sanity-imag-919ca0.iframe.bundle.js:145271:16)
    at HTMLUnknownElement.callCallback (http://localhost:3000/vendors-node_modules_ebay_nice-modal-react_lib_esm_index_js-node_modules_gogaille_sanity-imag-919ca0.iframe.bundle.js:130167:14)
    at Object.invokeGuardedCallbackDev (http://localhost:3000/vendors-node_modules_ebay_nice-modal-react_lib_esm_index_js-node_modules_gogaille_sanity-imag-919ca0.iframe.bundle.js:130216:16)
    at invokeGuardedCallback (http://localhost:3000/vendors-node_modules_ebay_nice-modal-react_lib_esm_index_js-node_modules_gogaille_sanity-imag-919ca0.iframe.bundle.js:130278:31)
    at beginWork$1 (http://localhost:3000/vendors-node_modules_ebay_nice-modal-react_lib_esm_index_js-node_modules_gogaille_sanity-imag-919ca0.iframe.bundle.js:150181:7)
    at performUnitOfWork (http://localhost:3000/vendors-node_modules_ebay_nice-modal-react_lib_esm_index_js-node_modules_gogaille_sanity-imag-919ca0.iframe.bundle.js:148993:12)
    at workLoopSync (http://localhost:3000/vendors-node_modules_ebay_nice-modal-react_lib_esm_index_js-node_modules_gogaille_sanity-imag-919ca0.iframe.bundle.js:148924:5)

And my GlobalStyles component:

import theme from "guidelines/Theme/theme";

const GlobalStyles = () => (
  <style global jsx>{`
    html {
      min-height: 100vh;
    }

    body,
    #__next {
      /**
       * Mobile viewport bug fix
       * @see https://allthingssmitty.com/2020/05/11/css-fix-for-100vh-in-mobile-webkit/
       */
      min-height: 100vh;
      min-height: fill-available;

      background-color: ${theme.color.background.cream};
    }

    html,
    body {
      margin: 0;
      padding: 0;
    }

    * {
      box-sizing: border-box;
    }
  `}</style>
);

Additional context
Next.js v12.0.7

react 18, storybook 6.5 issue

Describe the bug

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"18.1.0" from the root project
npm ERR!   peerOptional react@"^16.8.0 || ^17.0.0 || ^18.0.0" from @storybook/[email protected]
npm ERR!   node_modules/@storybook/addon-actions
npm ERR!     dev @storybook/addon-actions@"6.5.3" from the root project
npm ERR!     peer @storybook/addon-actions@"^6.0.0" from [email protected]
npm ERR!     node_modules/storybook-addon-next
npm ERR!       dev storybook-addon-next@"1.6.2" from the root project
npm ERR!   2 more (react-dom, next)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0 || ^17.0.0" from [email protected]
npm ERR! node_modules/storybook-addon-next
npm ERR!   dev storybook-addon-next@"1.6.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\shala\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\shala\AppData\Local\npm-cache\_logs\2022-05-20T07_58_57_872Z-debug-0.log

Your minimal, reproducible example

just use the storybook 6.5.3

Steps to reproduce

react 18,
storybook 6.5.3

Expected behavior

i expect it to install :)

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

windows

storybook-addon-next version

1.6.2

Additional context

No response

WebpackOptionsValidationError in 1.4.1

Describe the bug

When I run the command npm run storybook with v1.4.1, the error occurs.

Here is the log.

info @storybook/react v6.4.18
info
info => Loading presets
info => Serving static files from ./.\public at /
(node:14304) DeprecationWarning: You have specified an invalid glob, we've attempted to fix it, please ensure that the glob you specify is valid. See: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#correct-globs-in-mainjs
(Use `node --trace-deprecation ...` to show where the warning was created)
info => Using implicit CSS loaders
info => Using default Webpack4 setup
ERR! WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
ERR!  - configuration.module.rules[12].type should be one of these:
ERR!    "javascript/auto" | "javascript/dynamic" | "javascript/esm" | "json" | "webassembly/experimental"
ERR!    -> Module type to use for the module
ERR!     at webpack (C:\Users\hskco\OneDrive\바탕 화면\dev\next-storybook-image-test\node_modules\webpack\lib\webpack.js:31:9)
ERR!     at Object.start (C:\Users\hskco\OneDrive\바탕 화면\dev\next-storybook-image-test\node_modules\@storybook\builder-webpack4\dist\cjs\index.js:92:18)
ERR!     at async Promise.all (index 0)
ERR!     at async storybookDevServer (C:\Users\hskco\OneDrive\바탕 화면\dev\next-storybook-image-test\node_modules\@storybook\core-server\dist\cjs\dev-server.js:126:28)
ERR!     at async buildDevStandalone (C:\Users\hskco\OneDrive\바탕 화면\dev\next-storybook-image-test\node_modules\@storybook\core-server\dist\cjs\build-dev.js:115:31)
ERR!     at async buildDev (C:\Users\hskco\OneDrive\바탕 화면\dev\next-storybook-image-test\node_modules\@storybook\core-server\dist\cjs\build-dev.js:161:5)
ERR!  WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
ERR!  - configuration.module.rules[12].type should be one of these:
ERR!    "javascript/auto" | "javascript/dynamic" | "javascript/esm" | "json" | "webassembly/experimental"
ERR!    -> Module type to use for the module
ERR!     at webpack (C:\Users\hskco\OneDrive\바탕 화면\dev\next-storybook-image-test\node_modules\webpack\lib\webpack.js:31:9)
ERR!     at Object.start (C:\Users\hskco\OneDrive\바탕 화면\dev\next-storybook-image-test\node_modules\@storybook\builder-webpack4\dist\cjs\index.js:92:18)
ERR!     at async Promise.all (index 0)
ERR!     at async storybookDevServer (C:\Users\hskco\OneDrive\바탕 화면\dev\next-storybook-image-test\node_modules\@storybook\core-server\dist\cjs\dev-server.js:126:28)
ERR!     at async buildDevStandalone (C:\Users\hskco\OneDrive\바탕 화면\dev\next-storybook-image-test\node_modules\@storybook\core-server\dist\cjs\build-dev.js:115:31)
ERR!     at async buildDev (C:\Users\hskco\OneDrive\바탕 화면\dev\next-storybook-image-test\node_modules\@storybook\core-server\dist\cjs\build-dev.js:161:5)

WARN Broken build, fix the error above.
WARN You may need to refresh the browser.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! next-storybook-image-test@ storybook: `start-storybook -p 6006`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the next-storybook-image-test@ storybook script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.    

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\hskco\AppData\Roaming\npm-cache\_logs\2022-02-06T07_30_05_523Z-debug.log   

But It works well with v1.4.0.

Your minimal, reproducible example

Local

Steps to reproduce

\1. Create a project with next

npx create-next-app test

\2. Install the package

npm install -D storybook-addon-next

\3. Add the addon in main.js

module.exports = {
  stories: ["../components/**/*.stories.(js|jsx|ts|tsx)"],
  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "storybook-addon-next",
  ],
  framework: "@storybook/react",
  staticDirs: ["../public"],
};

\4. Run storybook

npm run storybook

Expected behavior

Run storybook without errors.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Windows

Here are packages that I installed

  "dependencies": {
    "@emotion/react": "^11.7.1",
    "@emotion/styled": "^11.6.0",
    "next": "12.0.10",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "storybook-addon-next": "^1.4.1"
  },
  "devDependencies": {
    "@babel/core": "^7.17.0",
    "@storybook/addon-actions": "^6.4.18",
    "@storybook/addon-essentials": "^6.4.18",
    "@storybook/addon-links": "^6.4.18",
    "@storybook/react": "^6.4.18",
    "babel-loader": "^8.2.3",
    "eslint": "8.8.0",
    "eslint-config-next": "12.0.10"
  }

storybook-addon-next version

v1.4.1

Additional context

No response

Links for the docs and tailwindcss example are broken

Describe the bug

Clicking links for all the examples lead to a page Not Found, and all of the links under Table of Contents and Supported features do not work, as do some in the contents of the article. Seems like all of the hashed id's are not set for the links to go to that element of the page.

I was able to find the repo for tailwindcss example based on the URL params though, but should be fixed to prevent any confusion

Your minimal, reproducible example

https://storybook.js.org/addons/storybook-addon-next

Steps to reproduce

  1. Scroll down and click any of the links under Table of Contents, Supported Features, or Examples
  2. The page will say Not Found

Expected behavior

Expected to see a working github page for the Example links, and expected the other links to bring me to other parts of the page

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOS
Firefox 97.0.1 (64 bit)

storybook-addon-next version

1.6.1

Additional context

No response

Doesn't support AVIF format

Describe the bug

Next image loader doesn't support avif format due to the use of the package image-size which doesn't support avif

Your minimal, reproducible example

None

Steps to reproduce

Add an <Image src="mum.avif" /> in a component which has a story.
Run Storybook
Crash with this stack trace:

ModuleBuildError: Module build failed (from ./node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js):
TypeError: unsupported file type: undefined (file: undefined)
    at lookup (/Users/johann/Dev/lab/template/node_modules/image-size/dist/index.js:42:11)
    at imageSize (/Users/johann/Dev/lab/template/node_modules/image-size/dist/index.js:98:16)
    at Object.nextImageLoaderStub (/Users/johann/Dev/lab/template/node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js:12:56)
    at processResult (/Users/johann/Dev/lab/template/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/NormalModule.js:758:19)
    at /Users/johann/Dev/lab/template/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/NormalModule.js:860:5
    at /Users/johann/Dev/lab/template/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:400:11
    at /Users/johann/Dev/lab/template/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:252:18
    at runSyncOrAsync (/Users/johann/Dev/lab/template/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:156:3)
    at iterateNormalLoaders (/Users/johann/Dev/lab/template/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:251:2)
    at /Users/johann/Dev/lab/template/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:224:4
    at /Users/johann/Dev/lab/template/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/NormalModule.js:834:15
    at Array.eval (eval at create (/Users/johann/Dev/lab/template/node_modules/@storybook/builder-webpack5/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)
    at runCallbacks (/Users/johann/Dev/lab/template/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:27:15)
    at /Users/johann/Dev/lab/template/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:200:4
    at /Users/johann/Dev/lab/template/node_modules/graceful-fs/graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)

WARN Broken build, fix the error above.

Expected behavior

Support avif format

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: MacOS Monterey 12.6, M1 pro chip
  • Chrome

storybook-addon-next version

1.6.9

Additional context

Could be solved by using a package that supports avif format to get dimensions of images (e.g probe-image-size)

Dont resolve paths from tsconfig

Describe the bug

Nextjs automatically support tsconfig's paths and base url while addon add only root path to module resolution.

export const configureAbsoluteImports = (baseConfig: WebpackConfig): void => void baseConfig.resolve?.modules?.push(path.resolve()) here

Your minimal, reproducible example

https://github.com/StephanAksenchenko/Sb-addon-next-bug

Steps to reproduce

  1. use node 16.14.0
  2. yarn
  3. yarn dev // run development server and it works right
  4. yarn storybook // get exception about module resolution

Expected behavior

I expect it should work identically

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Os - linux
Node - 16.14.0

storybook-addon-next version

v 1.6.2

Additional context

No response

Nextjs Image Error message Failed to parse src "static/media/public/logo.jpeg" on `next/image`

Describe the bug

Hello and thank you for this repo

I suspect this is more a problem with my code than your plugin but this is the issue I'm encountering.

Failed to parse src "static/media/public/logo.jpeg" on next/image, if using relative image it must start with a leading slash "/" or be an absolute URL (http:// or https://)

The image does exist at: http://localhost:6006/logo.jpeg

I have tried #72 and a few other things.

Here is a POC repo - https://github.com/Bowriverstudio/faustwp-storybook

Problem is in this story - components/TestImage/tests/TestImage.stories.jsx

Thank you

Your minimal, reproducible example

https://github.com/Bowriverstudio/faustwp-storybook

Steps to reproduce

Download https://github.com/Bowriverstudio/faustwp-storybook

npm i 
npm run storybook

Look at http://localhost:6006/?path=/story/example-testimage--test-image-story

Expected behavior

I expect to see an image

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

macOS

storybook-addon-next version

1.6.9

Additional context

No response

WebpackOptionsValidationError when starting

Describe the bug

After adding this addon to a fresh NextJS and Storybook and storybook-addon-next installation all with default configuration, and attempting to start Storybook, I have an error.

Your minimal, reproducible example

Run commands below

Steps to reproduce

  1. npx create-next-app@latest bug
  2. cd bug
  3. npx sb init, say yes or no to eslintPlugin question, doesn't make a difference
  4. npm i -D --force storybook-addon-next (force needed because otherwise peer dependency fails; see #68 which isn't yet released)
  5. Edit .storybook/main.js, add 'storybook-addon-nextto the end (or start, no difference) of theaddons` array
  6. npm run storybook
  7. See error:
info @storybook/react v6.4.22
info
info => Loading presets
info => Using implicit CSS loaders
info => Using default Webpack4 setup
ERR! WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
ERR!  - configuration.module.rules[12].type should be one of these:
ERR!    "javascript/auto" | "javascript/dynamic" | "javascript/esm" | "json" | "webassembly/experimental"
ERR!    -> Module type to use for the module
ERR!     at webpack (/path/to/bug/node_modules/webpack/lib/webpack.js:31:9)
ERR!     at Object.start (/path/to/bug/node_modules/@storybook/builder-webpack4/dist/cjs/index.js:92:18)
ERR!     at async Promise.all (index 0)
ERR!     at async storybookDevServer (/path/to/bug/node_modules/@storybook/core-server/dist/cjs/dev-server.js:126:28)
ERR!     at async buildDevStandalone (/path/to/bug/node_modules/@storybook/core-server/dist/cjs/build-dev.js:115:31)
ERR!     at async buildDev (/path/to/bug/node_modules/@storybook/core-server/dist/cjs/build-dev.js:161:5)
ERR!  WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
ERR!  - configuration.module.rules[12].type should be one of these:
ERR!    "javascript/auto" | "javascript/dynamic" | "javascript/esm" | "json" | "webassembly/experimental"
ERR!    -> Module type to use for the module
ERR!     at webpack (/path/to/bug/node_modules/webpack/lib/webpack.js:31:9)
ERR!     at Object.start (/path/to/bug/node_modules/@storybook/builder-webpack4/dist/cjs/index.js:92:18)
ERR!     at async Promise.all (index 0)
ERR!     at async storybookDevServer (/path/to/bug/node_modules/@storybook/core-server/dist/cjs/dev-server.js:126:28)
ERR!     at async buildDevStandalone (/path/to/bug/node_modules/@storybook/core-server/dist/cjs/build-dev.js:115:31)
ERR!     at async buildDev (/path/to/bug/node_modules/@storybook/core-server/dist/cjs/build-dev.js:161:5)

WARN Broken build, fix the error above.
WARN You may need to refresh the browser.

Expected behavior

Storybook starts

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Linux
  • Browser: n/a

storybook-addon-next version

1.6.2

Additional context

I had to install the package with --force, since #68 is not yet released.

Error: NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted

Describe the bug

I need to wrap my custom StoreProvider provider in decorator

export const decorators = [
  (Story, context) => (
          <StoreProvider>
              <Story />
          </StoreProvider>
  ),
]

inside my StoreProvider (react context) got wrote useRouter hook from nextjs..
because of decorator is render outside from nextjs.. so how can I solve it?

I am using nextjs 13

Your minimal, reproducible example

Steps to reproduce

none, private project

Expected behavior

expect next router to be mounted

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

  • OS: Macos

storybook-addon-next version

v1.6.10

Additional context

No response

External images break with next v12.1.5

Describe the bug

The following component works in storybook on with [email protected]:

import React from "react";
import Image from "next/image";

export default {
  title: "Example/Image",
  component: Image,
  argTypes: {
    backgroundColor: { control: "color" },
  },
};

const Template = (args) => (
  <Image src="https://via.placeholder.com/100x100" width={100} height={100} />
);

export const ExampleStoryWithNextImage = Template.bind({});

On next v12.1.5, it breaks however (see attached screenshots below).

Your minimal, reproducible example

https://github.com/romandecker/storybook-addon-next-image-issue-mre

Steps to reproduce

  1. Check out the MRE repo
  2. npm install
  3. npm run storybook
  4. Open http://localhost:6006/?path=/story/example-image--example-story-with-next-image

Note that if you change the version of next in package.json to v12.1.4, and re-run npm install and npm run storybook, it will work.

Expected behavior

I expected the external image to work with next v12.1.5 just like it did in v12.1.4:

image

How often does this bug happen?

Every time

Screenshots or Videos

[email protected]:
image

[email protected]:
image

Platform

  • Mac OS 11.6.4
  • node v16.14.0
  • next.js v12.1.5

storybook-addon-next version

1.6.2

Additional context

No response

Image domain warning >= Next.js v12.1.5

Describe the bug

Receiving the following error message: Invalid src prop (http://loremflickr.com/640/480/transport) on next/image, hostname "loremflickr.com" is not configured under images in your next.config.js``

Issue happens with Next.js >= v12.1.5 https://github.com/vercel/next.js/releases/tag/v12.1.5

Your minimal, reproducible example

Steps to reproduce

  1. Use Storybook and Next.js >= v12.1.5
  2. Use an image from an external domain in your Image Component
  3. Error

Expected behavior

Remote Images from an external domain should work as they did before Next.js v12.1.5

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • Platform: Mac

storybook-addon-next version

v1.6.2

Additional context

No response

Does not work with next/future/image

Describe the bug

Storybook gives the error:

The "next/future/image" component is experimental and may be subject to breaking changes. To enable this experiment, please include experimental: { images: { allowFutureImage: true } } in your next.config.js file.

Your minimal, reproducible example

None

Steps to reproduce

  1. Create component with import NextImage from 'next/future/image'
  2. Add this component to storybook
  3. Run storybook but it just fails with the above error

Expected behavior

Storybook start normally

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • Windows

storybook-addon-next version

v 1.6.7

Additional context

No response

Autoprefixer not working

Describe the bug

I'm trying to use CSS modules with SCSS and have come up against an issue where the autoprefixer is not working on storybook, but working correctly when I run NextJS.

The mask-image property is not being prefixed to support Chrome and the webkit browsers.

Screenshot 2022-08-03 at 15 14 13

Your minimal, reproducible example

https://stackblitz.com/edit/nextjs-a7vvxx

Steps to reproduce

.storybook/main.js

module.exports = {
  stories: [
    "../components/**/*.stories.mdx",
    "../components/**/*.stories.@(js|jsx|ts|tsx)",
  ],
  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions",
    "storybook-addon-next",
  ],
  framework: "@storybook/react",
  core: {
    builder: "@storybook/builder-webpack5",
  },
  staticDirs: ["../public"],
};

.browserlistrc

defaults
last 2 versions
not IE 11

scss

.playing {
  width: 50px;
  height: 50px;
  background: #FFFFFF;
  mask-image: url(https://upload.wikimedia.org/wikipedia/commons/0/03/Font_Awesome_5_solid_play-circle.svg);
  mask-mode: alpha;
}

deps

"dependencies": {
    "@mantine/core": "^4.2.12",
    "@mantine/hooks": "^4.2.12",
    "@mantine/next": "^4.2.12",
    "classnames": "^2.3.1",
    "date-fns": "^2.29.1",
    "framer-motion": "^6.5.1",
    "next": "12.2.2",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.18.9",
    "@storybook/addon-actions": "^6.5.9",
    "@storybook/addon-essentials": "^6.5.9",
    "@storybook/addon-interactions": "^6.5.9",
    "@storybook/addon-links": "^6.5.9",
    "@storybook/addon-postcss": "^3.0.0-alpha.1",
    "@storybook/builder-webpack5": "^6.5.9",
    "@storybook/manager-webpack5": "^6.5.9",
    "@storybook/react": "^6.5.9",
    "@storybook/testing-library": "^0.0.13",
    "@types/node": "18.0.6",
    "@types/react": "18.0.15",
    "@types/react-dom": "18.0.6",
    "babel-loader": "^8.2.5",
    "eslint": "8.20.0",
    "eslint-config-next": "12.2.2",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-storybook": "^0.6.1",
    "postcss": "^8.4.14",
    "sass": "^1.54.0",
    "storybook-addon-next": "^1.6.7",
    "stylelint": "^14.9.1",
    "stylelint-config-idiomatic-order": "^8.1.0",
    "stylelint-config-prettier-scss": "^0.0.1",
    "stylelint-config-standard-scss": "^5.0.0",
    "typescript": "4.7.4",
    "typescript-plugin-css-modules": "^3.4.0"
  }

Expected behavior

Screenshot 2022-08-03 at 15 14 20

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOS, Chrome

storybook-addon-next version

1.6.7

Additional context

none

Image doesn't support the `loader` prop

Describe the bug

I'm not sure if this is related to #67

I am building a site which loads images from various different sources. Next's next/image component allows a loader prop which allows me to pass in a function which generates URLs for a given image at various different widths.

I have different loader functions which produce different aspect ratios, and that sort of thing.

It seems that when run via storybook-addon-next, the loader prop is ignored or overruled, and I get the plain src coming through, which is not an actual loadable URL. This would also be the case if using some built-in loaders -- cloudinary for sure and possibly others.

Your minimal, reproducible example

Sorry, none

Steps to reproduce

import { Story, ComponentMeta } from "@storybook/react";

import Image from "next/image";

export default {
  title: "ImageTest",
  component: ImageTest,
} as ComponentMeta<typeof ImageTest>;

export const ImageTest: Story = () => (
  <Image
    src="my-untranslated-src"
    alt=""
    layout="responsive"
    loader={({ src, width, quality }) => `https://placekitten.com/${width}/${width}`}
    width={400}
    height={300}
  />
);

This loader is obviously pretend.

Expected behavior

This ought to come out with a kitten image, but it'll result in a broken image because storybook will render an image with "my-untranslated-src" as the source, and there is no such image.

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

n/a

storybook-addon-next version

v1.6.6

Additional context

No response

Getting error "no such file or directory, stat 'tsconfig.json'" on running Storybook

Describe the bug

Since updating to version 1.6.4, I'm getting the above error. Our project does not use a tsconfig.json file. As I understand, support for tsconfig.json was added in this version.

Might this be a bug or can one configure to not search for tsconfig.json?

Your minimal, reproducible example

https://github.com/wolfram-ostec/storybook-addon-next-no-tsconfig

Steps to reproduce

  1. Clone the reproducible example repo
  2. Run yarn install
  3. Run yarn storybook

Expected behavior

I expected Storybook to run without a tsconfig.json

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • Linux 5.16.1-051601-generic x86_64

storybook-addon-next version

v1.6.4

Additional context

No response

Error when starting, when using Typescript

Describe the bug

From a fresh Next installation with Typescript, and a fresh Storybook installation with Webpack 5, I am getting a Error: Cannot find module 'webpack/lib/util/makeSerializable.js' error when I try to start Storybook.

Your minimal, reproducible example

See commands below

Steps to reproduce

  1. npx create-next-app@latest bug --typescript
  2. cd bug
  3. npx sb init --builder webpack5 -- in my test I said yes to the linter question
  4. npm i -D --force storybook-addon-next
  5. Edit .storybook/main.js, add storybook-addon-next to the end of the addons array
  6. npm run storybook
  7. See error:
Error: Cannot find module 'webpack/lib/util/makeSerializable.js'
Require stack:
- /tmp/bug/node_modules/@storybook/react-docgen-typescript-plugin/dist/dependency.js
- /tmp/bug/node_modules/@storybook/react-docgen-typescript-plugin/dist/plugin.js
- /tmp/bug/node_modules/@storybook/react-docgen-typescript-plugin/dist/index.js
- /tmp/bug/node_modules/@storybook/react/dist/cjs/server/framework-preset-react-docgen.js
- /tmp/bug/node_modules/@storybook/core-common/dist/cjs/presets.js
- /tmp/bug/node_modules/@storybook/core-common/dist/cjs/index.js
- /tmp/bug/node_modules/@storybook/core-server/dist/cjs/index.js
- /tmp/bug/node_modules/@storybook/core/dist/cjs/server.js
- /tmp/bug/node_modules/@storybook/core/server.js
- /tmp/bug/node_modules/@storybook/react/dist/cjs/server/index.js
- /tmp/bug/node_modules/@storybook/react/bin/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/tmp/bug/node_modules/@storybook/react-docgen-typescript-plugin/dist/dependency.js:6:55)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at /tmp/bug/node_modules/@storybook/react-docgen-typescript-plugin/dist/plugin.js:108:42
    at Hook.eval [as call] (eval at create (/tmp/bug/node_modules/@storybook/builder-webpack5/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:374:1)
    at Hook.CALL_DELEGATE [as _call] (/tmp/bug/node_modules/@storybook/builder-webpack5/node_modules/webpack/node_modules/tapable/lib/Hook.js:14:14)
    at Compiler.newCompilation (/tmp/bug/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/Compiler.js:1122:26)
    at /tmp/bug/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/Compiler.js:1166:29 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/tmp/bug/node_modules/@storybook/react-docgen-typescript-plugin/dist/dependency.js',
    '/tmp/bug/node_modules/@storybook/react-docgen-typescript-plugin/dist/plugin.js',
    '/tmp/bug/node_modules/@storybook/react-docgen-typescript-plugin/dist/index.js',
    '/tmp/bug/node_modules/@storybook/react/dist/cjs/server/framework-preset-react-docgen.js',
    '/tmp/bug/node_modules/@storybook/core-common/dist/cjs/presets.js',
    '/tmp/bug/node_modules/@storybook/core-common/dist/cjs/index.js',
    '/tmp/bug/node_modules/@storybook/core-server/dist/cjs/index.js',
    '/tmp/bug/node_modules/@storybook/core/dist/cjs/server.js',
    '/tmp/bug/node_modules/@storybook/core/server.js',
    '/tmp/bug/node_modules/@storybook/react/dist/cjs/server/index.js',
    '/tmp/bug/node_modules/@storybook/react/bin/index.js'
  ]
}

Expected behavior

Storybook starts

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Linux
  • Browser: n/a

storybook-addon-next version

1.6.2

Additional context

No response

Seems to break svg's in introduction.stories.mdx file

Describe the bug

With addon-next in .storybook/main.js and svg's images in introduction.stories.mdx didn't render. I remove storybook-addon-next and images render again.
Edit: But this is a small thing. Otherwise. Removed all boilerplate. Next images as well as mui icons works fine. (thumb up!)

module.exports = {
stories: [
'../stories//*.stories.mdx',
'../stories/
/*.stories.@(js|jsx|ts|tsx)'
],
addons: [
'storybook-addon-next'
'@storybook/addon-a11y',
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
],
framework: '@storybook/react',
core: {
builder: 'webpack5'
}
}

image

Your minimal, reproducible example

Steps to reproduce

add 'storybook-addon-next' and run 'npm run storybook

Expected behavior

svg should be visible from mdx files

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

Windows 10

storybook-addon-next version

v1.4.3

Additional context

No response

Next/image with imgix loader

Describe the bug

Does not add absolute path to the imgix server for the img src.

Your minimal, reproducible example

Sorry no repo...

Steps to reproduce

Use next/image component in a story with the following configuration:

next.config

  images: {
    loader: "imgix",
    path: "https://my-account.imgix.net",
  },

Component with next/image

<Image src={"7f552320-6810-5a2d-8a47-521b22068ae5"} alt={"Alt"} width={42} height={42} />

Expected behavior

When running Next (yarn dev) the img src will automatically be set to https://my-account.imgix.net/7f552320-6810-5a2d-8a47-521b22068ae5.

When running Storybook the img src will only be 7f552320-6810-5a2d-8a47-521b22068ae5 right now. This results in a load to localhost and a 404 response.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOS

storybook-addon-next version

v1.6.2

Additional context

No response

Next12.2 future/image support

Describe the bug

Using the experimental "allowFutureImage" with storybook, it throw Error.

The "next/future/image" component is experimental and may be subject to breaking changes. To enable this experiment, please include `experimental: { images: { allowFutureImage: true } }` in your next.config.js file.

Your minimal, reproducible example

nextjs example with-storybook-app

Steps to reproduce

  1. npx create-next-app --example with-storybook with-storybook-app
  2. add experimental config
// next.config.js
module.exports = {
  ...
  experimental: {
    images: {
      allowFutureImage: true,
    },
  },
}
  1. replace "next/image" to "next/future/image"
// pages/nextjsImages.js
import Image from 'next/future/image'

Expected behavior

with next.config.js setup, the stories including future/image should load without error.

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

  • mac OS
  • Chrome (102.0.5005.115)

storybook-addon-next version

1.6.7

Additional context

No response

next-image-loader-stub error when trying to use @svgr/webpack for svg importing

Describe the bug

With a fresh Next 12, Storybook with webpack 5 and storybook-addon-next setup I can't use SVGR for the importing of SVGs.

When using the following next.config.js I would like to use the addon to import any image (except svg) to be imported like Next would normally do it.

module.exports = {
  reactStrictMode: true,
  webpack(config) {
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack']
    });
    return config
  }
}

So just with above configuration, the plugin will import a StaticImageData object for SVGs and bypass the SVGR loader entirely.

Unfortunately, when running storybook with the addon and the added svg configuration to the main.js will throw an error.

const path = require('path');

module.exports = {
  stories: [
    "../stories/**/*.stories.mdx",
    "../stories/**/*.stories.@(js|jsx|ts|tsx)"
  ],
  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions",
    {
      name: 'storybook-addon-next',
      options: {
        nextConfigPath: path.resolve(__dirname, '../next.config.js')
      }
    }
  ],
  framework: "@storybook/react",
  core: {
    "builder": "webpack5"
  },
  webpackFinal: async (config) => {
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack']
    });
    return config
  },
}

This error occurs during building with the configuration above.

ModuleBuildError: Module build failed (from ./node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js):
TypeError: unsupported file type: undefined (file: undefined)
    at lookup (/Users/jeroen.roumen/Development/storybook-webpack5/node_modules/image-size/dist/index.js:51:11)
    at imageSize (/Users/jeroen.roumen/Development/storybook-webpack5/node_modules/image-size/dist/index.js:109:16)
    at Object.nextImageLoaderStub (/Users/jeroen.roumen/Development/storybook-webpack5/node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js:12:56)
    at processResult (/Users/jeroen.roumen/Development/storybook-webpack5/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/NormalModule.js:758:19)
    at /Users/jeroen.roumen/Development/storybook-webpack5/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/NormalModule.js:860:5
    at /Users/jeroen.roumen/Development/storybook-webpack5/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:399:11
    at /Users/jeroen.roumen/Development/storybook-webpack5/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:251:18
    at runSyncOrAsync (/Users/jeroen.roumen/Development/storybook-webpack5/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:156:3)
    at iterateNormalLoaders (/Users/jeroen.roumen/Development/storybook-webpack5/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:250:2)
    at iterateNormalLoaders (/Users/jeroen.roumen/Development/storybook-webpack5/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:239:10)
    at /Users/jeroen.roumen/Development/storybook-webpack5/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:254:3
    at context.callback (/Users/jeroen.roumen/Development/storybook-webpack5/node_modules/@storybook/builder-webpack5/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at cb (util.js:290:31)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
ModuleBuildError: Module build failed (from ./node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js):
TypeError: unsupported file type: undefined (file: undefined)
    at lookup (/Users/jeroen.roumen/Development/storybook-webpack5/node_modules/image-size/dist/index.js:51:11)
    at imageSize (/Users/jeroen.roumen/Development/storybook-webpack5/node_modules/image-size/dist/index.js:109:16)

It seems the addon is not detecting to not use the stub or something else might be going on there.

Your minimal, reproducible example

Can provide a zip with a project

Steps to reproduce

  1. Create a fresh Next 12 project
  2. Setup Storybook with webpack 5
  3. Add Next storybook addon
  4. Add @svgr/webpack
  5. Edit next.config.js to set a test for .svg and use @svgr/webpack as loader
  6. Import a .svg into a .stories file
  7. Try to run yarn storybook and it should present the error from above

Expected behavior

As a user I would like the addon to check my current next.config.js webpack configuration and use SVGR to import .svg files in storybook alongside normal images which would use the next-image-loader-stub.

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

  • OS: macOS 11.6.4
  • Browser: Firefox 99

storybook-addon-next version

1.6.2

Additional context

No response

Stoyybook Addon Next break Storybook when is used with Vite builder

Describe the bug

When use this plugin with Vite builder Storybook always show the error Invalid Version: undefined

Your minimal, reproducible example

updating

Steps to reproduce

Install Storybook with Vite builder and this plugin

Expected behavior

That this plugin could work with Vite builder

How often does this bug happen?

No response

Screenshots or Videos

imagen

Platform

MacOS 12.3.1

storybook-addon-next version

1.6.4

Additional context

No response

Does not work on Next canary version

Describe the bug

Storybook is started but gives the error:

530.manager.bundle.js:71222 
Warning: ReactDOM.render is no longer supported in React 18.
Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. 
Learn more: https://reactjs.org/link/switch-to-createroot

Your minimal, reproducible example

Default config from docs

Steps to reproduce

  1. Use next version 12.1.6
  2. It works
  3. Update to 12.1.7-canary.29
  4. It gives the above error

Expected behavior

Working Storybook

How often does this bug happen?

Every time

Screenshots or Videos

Снимок экрана 2022-06-04 в 18 44 46

Platform

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:24 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T8101
Binaries:
  Node: 14.17.5
  npm: 7.21.1
  Yarn: 1.22.11
  pnpm: N/A
Relevant packages:
  next: 12.1.7-canary.29
  react: 18.1.0
  react-dom: 18.1.0

storybook-addon-next version

^1.6.6

Additional context

Critical issue, can not work with storybook at next canary version

PostCSS plugin tailwindcss requires PostCSS 8.

Describe the bug
I'm facing an issue when I started storybook

To Reproduce
Steps to reproduce the behavior:

  1. Install storybook-addon-next: yarn add storybook-addon-next -D
  2. Add 'storybook-addon-next' to main.js file
  3. Lanch storybook: yarn storybook
  4. See error

CleanShot 2022-01-26 at 18 42 52

My package.json

"devDependencies": {
    "@babel/core": "^7.16.12",
    "@commitlint/cli": "^16.1.0",
    "@commitlint/config-conventional": "^16.0.0",
    "@next/bundle-analyzer": "^12.0.8",
    "@storybook/addon-a11y": "^6.4.14",
    "@storybook/addon-actions": "^6.4.14",
    "@storybook/addon-essentials": "^6.4.14",
    "@storybook/addon-links": "^6.4.14",
    "@storybook/addon-postcss": "^2.0.0",
    "@storybook/addons": "^6.4.14",
    "@storybook/builder-webpack5": "^6.4.14",
    "@storybook/manager-webpack5": "^6.4.14",
    "@storybook/react": "^6.4.14",
    "@storybook/theming": "^6.4.14",
    "@svgr/webpack": "^6.2.0",
    "@tailwindcss/forms": "^0.4.0",
    "@tailwindcss/typography": "^0.5.0",
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@types/react": "^17.0.38",
    "@types/tailwindcss": "^3.0.3",
    "@typescript-eslint/eslint-plugin": "^5.10.1",
    "@typescript-eslint/parser": "^5.10.1",
    "autoprefixer": "^10.4.2",
    "babel-jest": "^27.4.6",
    "babel-loader": "^8.2.3",
    "commitizen": "^4.2.4",
    "commitlint-config-gitmoji": "^2.2.5",
    "cz-customizable": "^6.3.0",
    "eslint": "8.6.0",
    "eslint-config-next": "^12.0.8",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-react": "^7.28.0",
    "eslint-plugin-react-hooks": "^4.3.0",
    "eslint-plugin-simple-import-sort": "^7.0.0",
    "eslint-plugin-storybook": "^0.5.5",
    "eslint-plugin-unused-imports": "^2.0.0",
    "husky": "^7.0.4",
    "identity-obj-proxy": "^3.0.0",
    "inquirer-fuzzy-path": "^2.3.0",
    "jest": "^27.4.7",
    "lint-staged": "^12.3.1",
    "next-sitemap": "^2.0.7",
    "plop": "^3.0.5",
    "postcss": "^8.4.5",
    "prettier": "^2.5.1",
    "prettier-plugin-tailwindcss": "^0.1.4",
    "react-test-renderer": "^17.0.2",
    "standard-version": "^9.3.2",
    "storybook-addon-next": "^1.3.1",
    "storybook-theme-css-vars": "^0.0.4",
    "tailwindcss": "^3.0.16",
    "typescript": "^4.5.5"
  },

Enabling react strict mode with this addon causes "Rendered more hooks than during the previous render." error.

Describe the bug

Before installing this addon, I was able to enable strict mode in storybook by doing:

reactOptions: {
    strictMode: true,
  }

in my main.ts as documented by this issue storybookjs/storybook#12734 and associated PR.

This was working fine, I would see my effects being called twice on mount.

Since adding this package, any combination of strictMode: true or putting reactStrictMode: true in the next.config.js I am using for this addon results in all stories throwing:

Error
Rendered more hooks than during the previous render.

Call Stack
 useHook
  vendors-node_modules_babel_runtime_helpers_esm_asyncToGenerator_js-node_modules_babel_runtime-285286.iframe.bundle.js:12364:13
 useMemoLike
  vendors-node_modules_babel_runtime_helpers_esm_asyncToGenerator_js-node_modules_babel_runtime-285286.iframe.bundle.js:12391:18
 useMemo
  vendors-node_modules_babel_runtime_helpers_esm_asyncToGenerator_js-node_modules_babel_runtime-285286.iframe.bundle.js:12403:10
 withOutline
  vendors-node_modules_babel_runtime_helpers_esm_asyncToGenerator_js-node_modules_babel_runtime-285286.iframe.bundle.js:11886:81
 undefined
  vendors-node_modules_babel_runtime_helpers_esm_asyncToGenerator_js-node_modules_babel_runtime-285286.iframe.bundle.js:12269:21
 undefined
  vendors-node_modules_babel_runtime_helpers_esm_asyncToGenerator_js-node_modules_babel_runtime-285286.iframe.bundle.js:34690:12
 undefined
  vendors-node_modules_babel_runtime_helpers_esm_asyncToGenerator_js-node_modules_babel_runtime-285286.iframe.bundle.js:34739:14
 renderWithHooks
  vendors-node_modules_babel_runtime_helpers_esm_asyncToGenerator_js-node_modules_babel_runtime-285286.iframe.bundle.js:139816:18
 mountIndeterminateComponent
  vendors-node_modules_babel_runtime_helpers_esm_asyncToGenerator_js-node_modules_babel_runtime-285286.iframe.bundle.js:143580:13
 beginWork
  vendors-node_modules_babel_runtime_helpers_esm_asyncToGenerator_js-node_modules_babel_runtime-285286.iframe.bundle.js:145093:16

Is this expected? Do you have an idea right off the bat of what is happening here?

I will fill in a valid reproduction if it's not immediately obvious to you why this might be happening. I believe the one liner in Steps to reproduce will cause this if you run one of your examples with it.

Steps to reproduce

  1. Add reactOptions: { strictMode: true } to your export from .storybook/main.js.
  2. Serve your storybook.

Expected behavior

I expect storybook's strict mode API to "just work".

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Mac OS
Next 13.1.1
Storybook 6.5.15
React 18.2.0

storybook-addon-next version

1.7.1

Additional context

No response

Next 12.1.5 error: Failed to parse src "static/media/public/nyan-cat.png"

Describe the bug

As of Next 12.1.5, this addon no longer seems to work with Next Image.

Full error message:

Error: 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://)
    at defaultLoader (http://localhost:6006/vendors-node_modules_storybook_addon-actions_dist_esm_preset_addArgs_js-generated-config-entr-68d96e.iframe.bundle.js:55971:23)
    at defaultImageLoader (http://localhost:6006/vendors-node_modules_storybook_addon-actions_dist_esm_preset_addArgs_js-generated-config-entr-68d96e.iframe.bundle.js:55790:16)
    at http://localhost:6006/vendors-node_modules_storybook_addon-actions_dist_esm_preset_addArgs_js-generated-config-entr-68d96e.iframe.bundle.js:55755:39
    at Array.map (<anonymous>)
    at generateImgAttrs (http://localhost:6006/vendors-node_modules_storybook_addon-actions_dist_esm_preset_addArgs_js-generated-config-entr-68d96e.iframe.bundle.js:55755:24)
    at ImageElement (http://localhost:6006/vendors-node_modules_storybook_addon-actions_dist_esm_preset_addArgs_js-generated-config-entr-68d96e.iframe.bundle.js:55896:183)
    at renderWithHooks (http://localhost:6006/vendors-node_modules_storybook_addon-actions_dist_esm_preset_addArgs_js-generated-config-entr-68d96e.iframe.bundle.js:79513:18)
    at mountIndeterminateComponent (http://localhost:6006/vendors-node_modules_storybook_addon-actions_dist_esm_preset_addArgs_js-generated-config-entr-68d96e.iframe.bundle.js:82339:13)
    at beginWork (http://localhost:6006/vendors-node_modules_storybook_addon-actions_dist_esm_preset_addArgs_js-generated-config-entr-68d96e.iframe.bundle.js:83577:16)
    at HTMLUnknownElement.callCallback (http://localhost:6006/vendors-node_modules_storybook_addon-actions_dist_esm_preset_addArgs_js-generated-config-entr-68d96e.iframe.bundle.js:68473:14)

Your minimal, reproducible example

https://github.com/rsanchez-forks/storybook-addon-next/tree/next-12.1.5-issue/examples/nextv12

Steps to reproduce

  1. In examples/nextv12, run yarn add [email protected]
  2. Run yarn storybook
  3. Go to Nextjs Images Page in storybook
  4. Observer error in storybook

Expected behavior

As a user, expect next-image to work within Storybook.

How often does this bug happen?

Every time

Screenshots or Videos

Screen Shot 2022-04-16 at 10 35 42 PM

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 100.0.4896.75

storybook-addon-next version

Main branch, Commit hash a7efc09

Additional context

Next 12.1.4 does not have the same issue.

Failed to load preset: /dist/preset.js

Describe the bug

I was unable to run storybook in the nextv12 example out of the box. Tried downgrading the next version to the explicit versions in the package.json file but still did not work.

image

Your minimal, reproducible example

1.6.7 repo

Steps to reproduce

  1. git clone project
  2. yarn on main folder
  3. cd examples/nextv12
  4. yarn
  5. yarn storybook

Expected behavior

As a user I expected to run storybook

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

  • OSx / macbook

storybook-addon-next version

1.6.7

Additional context

No response

Broken with css-loader >= 6.0.0

Describe the bug

Due to this breaking change on css-loader 6.0.0:

for url and import options Function type was removed in favor Object type with the filter property, i.e. before { url: () => true }, now { url: { filter: () => true } } and before { import: () => true }, now { import: { filter: () => true } }

And due to the the version constraint ^6.5.1 the addon is broken because of current css-loader config that uses old format

requiring [email protected] (before the breaking changes) is a workaround

Your minimal, reproducible example

the repo examples should all be failing on storybook start 🤔

Steps to reproduce

install with css-loader >6.0.0

Expected behavior

storybook should start

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOs

storybook-addon-next version

1.4.2

Additional context

No response

next 13 support

Describe the bug

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/next
npm ERR!   next@"13.0.0" from the root project
npm ERR!   peer next@"^8.1.1-canary.54 || >=9.0.0" from [email protected]
npm ERR!   node_modules/next-seo
npm ERR!     next-seo@"5.8.0" from the root project
npm ERR!   1 more (next-sitemap)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer next@"^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0" from [email protected]
npm ERR! node_modules/storybook-addon-next
npm ERR!   dev storybook-addon-next@"1.6.9" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/next
npm ERR!   peer next@"^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0" from [email protected]
npm ERR!   node_modules/storybook-addon-next
npm ERR!     dev storybook-addon-next@"1.6.9" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\shala\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\shala\AppData\Local\npm-cache\_logs\2022-10-25T22_25_34_802Z-debug-0.log
npm ERR! code 1
npm ERR! path E:\source\vizesizgezi
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c cd dataset && npm install && cd ../frontend && npm install && cd ../migrator && npm install && cd ../tasks && npm install && cd ../tools/image_gen && npm install && cd ../..

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\shala\AppData\Local\npm-cache\_logs\2022-10-25T22_25_21_001Z-debug-0.log

Your minimal, reproducible example

n/a

Steps to reproduce

upgrade next to 13.0.0.

Expected behavior

should install properly

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

any

storybook-addon-next version

1.6.9

Additional context

No response

Cannot find module {MY-FOLDER-NAME-CUT}

Describe the bug

I don't know why I'm facing the same error when I start storybook.

I tried 3 times with 3 different projects and my folder name is just cut off.

Your minimal, reproducible example

https://github.com/FrancoRATOVOSON/coeur-next

Steps to reproduce

  1. Install storybook-addon-next: yarn add storybook-addon-next -D
  2. Add 'storybook-addon-next' to main.js file
  3. Lanch storybook: yarn storybook
  4. See error

issue_1

Saw the same problem 2 times :

issue_2

Here's my package.json

"dependencies": {
    "next": "12.1.0",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "devDependencies": {
    "@babel/core": "^7.17.5",
    "@storybook/addon-actions": "^6.4.19",
    "@storybook/addon-essentials": "^6.4.19",
    "@storybook/addon-interactions": "^6.4.19",
    "@storybook/addon-links": "^6.4.19",
    "@storybook/builder-webpack5": "^6.4.19",
    "@storybook/manager-webpack5": "^6.4.19",
    "@storybook/react": "^6.4.19",
    "@storybook/testing-library": "^0.0.9",
    "@types/node": "17.0.21",
    "@types/react": "17.0.39",
    "babel-loader": "^8.2.3",
    "eslint": "8.10.0",
    "eslint-config-next": "12.1.0",
    "eslint-plugin-storybook": "^0.5.7",
    "storybook-addon-next": "^1.6.1",
    "typescript": "4.6.2"
  }

And my main.js

module.exports = {
  "stories": [
    "../stories/**/*.stories.mdx",
    "../stories/**/*.stories.@(js|jsx|ts|tsx)"
  ],
  "addons": [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions",
    "storybook-addon-next"
  ],
  "framework": "@storybook/react",
  "core": {
    "builder": "webpack5"
  }
}

It's an empty project I created to test the behavior and got the same issue.

Platform

  • OS : Windows 10

storybook-addon-next version

^1.6.1

Image experimental layout="raw" support

Describe the bug

I'm using the experimental "raw" layout but with storybook I get the following error:

The "raw" layout is currently experimental and may be subject to breaking changes. To use layout="raw", include experimental: { images: { layoutRaw: true } } in your next.config.js file.

image

I do have allowed this experimental feature in next.config.js, and also configured storybook main.js to use the next.config.js file ("nextConfigPath"). However it doesn't seem to work.

Are experimental features not supported, or is there anything I could do to make this work?

Your minimal, reproducible example

not yet...

Steps to reproduce

Create a storybook with an Image component with props layout="raw".

Expected behavior

If the experimental images: { layoutRaw: true, } is available in next.config.js, the Image component should load.

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

Ubuntu 20.04 (WSL2)
Next.js 12.1.4
Storybook 6.4.19
storybook-addon-next 1.6.2

storybook-addon-next version

1.6.2

Additional context

No response

Doesn't work when using Next.js's Runtime Configuration

Describe the bug

When a component that's in a story calls a function that calls getConfig, Storybook will error:

next_config__WEBPACK_IMPORTED_MODULE_0__["default"]() is undefined

loadConfig@http://localhost:6006/main.iframe.bundle.js:206:65

image

Your minimal, reproducible example

[email protected]:Vinnl/repro-storybook-addon-next-getconfig.git

Steps to reproduce

  1. git clone [email protected]:Vinnl/repro-storybook-addon-next-getconfig.git
  2. npm install
  3. npm run storybook
  4. Open the IndexPage story.

Expected behavior

A story with the page is opened, showing

{
    someKey: "some value",
  }

Instead, you see the error described above.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • Fedora Linux 35
  • Firefox 97

storybook-addon-next version

1.5.0

Additional context

No response

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Does not work with yarn workspaces

Describe the bug

When using in a project that is a yarn workspace (on a monorepo setup), the plugin fails to find modules because of node_modules being hoisted up to the root folder:

yarn storybook
yarn run v1.22.17
$ start-storybook -p 6006 -s public
info @storybook/react v6.4.18
info 
(node:61699) DeprecationWarning: --static-dir CLI flag is deprecated, see:

https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated---static-dir-cli-flag
(Use `node --trace-deprecation ...` to show where the warning was created)
info => Loading presets
info => Serving static files from ./public at /
info => Using implicit CSS loaders
ERR! Error: Cannot find module '<project-root>/storybook-addon-next/examples/with-tailwindcss/node_modules/next/package.json'
ERR! Require stack:
ERR! - <project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/utils.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/preset.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/core-common/dist/cjs/presets.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/core-common/dist/cjs/index.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/core-server/dist/cjs/index.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/core/dist/cjs/server.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/core/server.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/react/dist/cjs/server/index.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/react/bin/index.js
ERR!     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
ERR!     at Function.Module._load (node:internal/modules/cjs/loader:778:27)
ERR!     at Module.require (node:internal/modules/cjs/loader:1005:19)
ERR!     at require (node:internal/modules/cjs/helpers:102:18)
ERR!     at getNextjsVersion (<project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/utils.js:9:1)
ERR!     at configureStaticImageImport (<project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/images/webpack.js:14:50)
ERR!     at configureImages (<project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/images/webpack.js:8:5)
ERR!     at <project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/preset.js:29:35
ERR!     at Generator.next (<anonymous>)
ERR!     at fulfilled (<project-root>/storybook-addon-next/examples/node_modules/tslib/tslib.js:114:62)
ERR!  Error: Cannot find module '<project-root>/storybook-addon-next/examples/with-tailwindcss/node_modules/next/package.json'
ERR! Require stack:
ERR! - <project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/utils.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/preset.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/core-common/dist/cjs/presets.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/core-common/dist/cjs/index.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/core-server/dist/cjs/index.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/core/dist/cjs/server.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/core/server.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/react/dist/cjs/server/index.js
ERR! - <project-root>/storybook-addon-next/examples/node_modules/@storybook/react/bin/index.js
ERR!     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
ERR!     at Function.Module._load (node:internal/modules/cjs/loader:778:27)
ERR!     at Module.require (node:internal/modules/cjs/loader:1005:19)
ERR!     at require (node:internal/modules/cjs/helpers:102:18)
ERR!     at getNextjsVersion (<project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/utils.js:9:1)
ERR!     at configureStaticImageImport (<project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/images/webpack.js:14:50)
ERR!     at configureImages (<project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/images/webpack.js:8:5)
ERR!     at <project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/preset.js:29:35
ERR!     at Generator.next (<anonymous>)
ERR!     at fulfilled (<project-root>/storybook-addon-next/examples/node_modules/tslib/tslib.js:114:62) {
ERR!   code: 'MODULE_NOT_FOUND',
ERR!   requireStack: [
ERR!     '<project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/utils.js',
ERR!     '<project-root>/storybook-addon-next/examples/node_modules/storybook-addon-next/dist/preset.js',
ERR!     '<project-root>/storybook-addon-next/examples/node_modules/@storybook/core-common/dist/cjs/presets.js',
ERR!     '<project-root>/storybook-addon-next/examples/node_modules/@storybook/core-common/dist/cjs/index.js',
ERR!     '<project-root>/storybook-addon-next/examples/node_modules/@storybook/core-server/dist/cjs/index.js',
ERR!     '<project-root>/storybook-addon-next/examples/node_modules/@storybook/core/dist/cjs/server.js',
ERR!     '<project-root>/storybook-addon-next/examples/node_modules/@storybook/core/server.js',
ERR!     '<project-root>/storybook-addon-next/examples/node_modules/@storybook/react/dist/cjs/server/index.js',
ERR!     '<project-root>/storybook-addon-next/examples/node_modules/@storybook/react/bin/index.js'
ERR!   ]
ERR! }

WARN Broken build, fix the error above.
WARN You may need to refresh the browser.

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Your minimal, reproducible example

https://github.com/volkyeth/storybook-addon-next/tree/broken-with-yarn-workspaces

Steps to reproduce

git clone --branch broken-with-yarn-workspaces [email protected]:volkyeth/storybook-addon-next.git
cd storybook-addon-next/examples
yarn install
cd with-tailwindcss
yarn storybook

Expected behavior

Package should work with yarn workspaces

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

OS: MacOS

storybook-addon-next version

1.4.2

Additional context

I'm not sure what's the fix for this as I'm not very experienced at packaging libs. I'll try to look into it but if someone knows how to make it compatible please advise and I'll try to make a PR

Does not work with `@nrwl/react/plugins/storybook` addon

Describe the bug

Storybook gives the error:

ModuleBuildError: Module build failed (from ./node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js):
TypeError: Cannot read properties of undefined (reading 'replace')
    at Object.nextImageLoaderStub (/Users/anatoo/Workspace/xxx/xxx/node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js:7:75)
    at processResult (/Users/anatoo/Workspace/xxx/xxx/node_modules/webpack/lib/NormalModule.js:758:19)
    at /Users/anatoo/Workspace/xxx/xxx/node_modules/webpack/lib/NormalModule.js:860:5
    at /Users/anatoo/Workspace/xxx/xxx/node_modules/loader-runner/lib/LoaderRunner.js:400:11
    at /Users/anatoo/Workspace/xxx/xxx/node_modules/loader-runner/lib/LoaderRunner.js:252:18
    at runSyncOrAsync (/Users/anatoo/Workspace/xxx/xxx/node_modules/loader-runner/lib/LoaderRunner.js:156:3)
    at iterateNormalLoaders (/Users/anatoo/Workspace/xxx/xxx/node_modules/loader-runner/lib/LoaderRunner.js:251:2)
    at /Users/anatoo/Workspace/xxx/xxx/node_modules/loader-runner/lib/LoaderRunner.js:224:4
    at /Users/anatoo/Workspace/xxx/xxx/node_modules/webpack/lib/NormalModule.js:834:15
    at Array.eval (eval at create (/Users/anatoo/Workspace/xxx/xxx/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)
    at runCallbacks (/Users/anatoo/Workspace/xxx/xxx/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:27:15)

Your minimal, reproducible example

None

Steps to reproduce

  1. Add @nrwl/react/plugins/storybook addon to ".storybook/main.js"
  2. Run storybook but it just fail with the above error

Expected behavior

Storybook start normally

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: macOS

storybook-addon-next version

v1.6.7

Additional context

@nrwl/react/plugin/storybook add the below webpack loader rule.

{
  test: /\.(bmp|png|jpe?g|gif|webp|avif)$/,
  type: 'asset',
  parser: { dataUrlCondition: { maxSize: 10000 } }
} 

storybook-addon-next 's configureStaticImageImport function refer generator.filename option of the rule.

  const assetRule = rules?.find(
    rule =>
      typeof rule !== 'string' &&
      rule.test instanceof RegExp &&
      rule.test.test('test.jpg')
  ) as RuleSetRule
  assetRule.test = /\.(apng|eot|otf|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/
  rules?.push({
    test: /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,
    issuer: { not: /\.(css|scss|sass)$/ },
    use: [
      {
        loader: require.resolve('./next-image-loader-stub'),
        options: {
          filename: assetRule.generator?.filename // <<----
        }
      }
    ]
  })
  rules?.push({
    test: /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,
    issuer: /\.(css|scss|sass)$/,
    type: 'asset/resource',
    generator: {
      filename: assetRule.generator?.filename // <<----
    }
  })

https://github.com/RyanClementsHax/storybook-addon-next/blob/main/src/images/webpack.ts#L15-L41

As a result, the generator.filename option is undefined and the storybook is broken.

SassError: SassError: expected "{"

Describe the bug

SassError: SassError: expected "{".

2 │ import API from "!../../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js";
│ ^

components/Container/styles.module.scss 2:98 root stylesheet
at Object.loader (/Users/mikhailkiselyov/WebstormProjects/tajwork/node_modules/sass-loader/dist/index.js:69:14)
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):

Your minimal, reproducible example

https://sharemycode.io/c/3bc21b0

Steps to reproduce

start-storybook -p 6006

Expected behavior

Successful build

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOS Monterey (12.0.1 (21A559))
Google Chrome (101.0.4951.64 ARM)

storybook-addon-next version

^1.6.6

Additional context

main.js config

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

module.exports = {
  "stories": [
    "../**/*.stories.mdx",
    "../**/*.stories.@(js|jsx|ts|tsx)",
  ],
  "addons": [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions",
    "@storybook/preset-scss",
    "storybook-addon-next"
  ],
  "framework": "@storybook/react",
  "core": {
    "builder": "@storybook/builder-webpack5"
  },
  "webpackFinal": async (config) => {
    config.resolve.plugins = [
      ...(config.resolve.plugins || []),
      new TsconfigPathsPlugin({
        extensions: config.resolve.extensions,
      }),
    ];
    return config;
  },
}

preview.js config

import "../styles/globals.css";

export const parameters = {
  actions: { argTypesRegex: "^on[A-Z].*" },
  controls: {
    matchers: {
      color: /(background|color)$/i,
      date: /Date$/,
    },
  },
}

nextjs.config:

/** @type {import('next').NextConfig} */
const { i18n } = require("./next-i18next.config");
const path = require("path");

const nextConfig = {
  reactStrictMode: true,
  images: {
    domains: ["chelyabinsk.zarplata.ru", "cdn3.zp.ru"],
  },
  sassOptions: {
    includePaths: [path.join(__dirname, "styles")],
  },
  i18n,
};

module.exports = nextConfig;

Package resolution in local development broken

Describe the bug

When developing locally (i.e. yarn watch in the root directory and yarn storybook in any of the examples), the storybook command fails unable to find any of the packages required or resolved directly (i.e. require('package') or require.resolve('package').

Your minimal, reproducible example

This repo

Steps to reproduce

yarn watch in the root repo
yarn storybook in any of the examples

Expected behavior

storybook is able to build and start

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

WSL

storybook-addon-next version

1.4.3

Additional context

No response

Importing font files (*.woff, *.ttf)

Describe the bug

Loading fonts seems to be failing with:

ModuleBuildError: Module build failed (from ./node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js):
TypeError: unsupported file type: undefined (file: undefined)
    at lookup (/Users/.../node_modules/image-size/dist/index.js:52:11)
    at imageSize (/Users/.../node_modules/image-size/dist/index.js:104:16)

Webpack config shows that the font is being loaded via next-image-loader-stub:

{
    test: /\.(svg|ico|jpg|jpeg|png|apng|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,
        use: [
              {
                loader: '/Users/.../node_modules/storybook-addon-next/dist/images/next-image-loader-stub.js',
                options: { filename: 'static/media/[path][name][ext]' }
              }
        ]
  },

Perhaps it's because font files won't have a width and height?

const { width, height } = imageSizeOf(content)

Just guessing... Would love to hear your insights.
Thanks!

Your minimal, reproducible example

http://forking.example.on.codesandbox.fails.to.build

Steps to reproduce

  1. add a font static asset
  2. add css that imports font file
  3. storybook start fails

Expected behavior

I expected static file imports to work as before, but next-image-loader-stub seems to be breaking.

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

  • OS: MacOS X
  • Node 16

storybook-addon-next version

v1.3.1

Additional context

No response

Addon breaks SCSS support in `styled-jsx`

Describe the bug

The addon breaks styled-jsx with SCSS support using either @storybook/preset-scss or a webpack .scss rule (see below). The Stackblitz example is based off of this repo's nextv12 example.

Your minimal, reproducible example

https://stackblitz.com/edit/github-quwche?file=README.md

Steps to reproduce

  1. Open URL
  2. Project automatically loads Next.js example
  3. See the code runs with green text and no errors
  4. Start Storybook in new terminal or stop Next.js dev server: yarn storybook
  5. See console error about nested styles not being supported.
ModuleBuildError: Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: ~/storybook-addon-next-scss/pages/index.js: Nesting detected at 5:11. Unfortunately nesting is not supported by styled-jsx.
  1. Stop Storybook then remove or comment out storybook-addon-next in .storybook/main.js:L6
  2. Restart Storybook (yarn storybook) and see that Storybook works correctly and displays green text.

Expected behavior

With a working instance of Next.js and Storybook that supports SCSS in styled-jsx I expect that this would continue to work after adding storybook-addon-next.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS:
  • Browser:
    • Chromium 100.0.4896.88
    • Brave V1.37.116 (Chromium 100.0.4896.127)

storybook-addon-next version

1.6.2

Additional context

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.