Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'apply') #139

Closed
aronchick opened this issue Feb 13, 2024 · 4 comments
Closed

Cannot read properties of undefined (reading 'apply') #139

aronchick opened this issue Feb 13, 2024 · 4 comments

Comments

@aronchick
Copy link

I filed this on StackOverflow and they redirected me here (https://stackoverflow.com/questions/77985046/why-is-storybook-throwing-this-undefined-apply-error?noredirect=1#comment137483137_77985046)


If I remove the "initialize" in the middle, it works ... sort of. It fails with some other errors around Configure.mdx. So I followed the instructions[1] and I get the errors below. I can't quite figure out what I'm missing!

Here is the error:

Cannot read properties of undefined (reading 'apply')

Here is my preview.tsx:

import type { Preview } from "@storybook/react"
import {
  reactRouterParameters,
  withRouter,
} from "storybook-addon-react-router-v6"
import "../src/index.scss"
import { passthrough } from "msw"
import { setupWorker } from "msw/browser"
import { initialize, mswDecorator } from 'msw-storybook-addon';
import { handlers as storyBookHandlers } from "../.storybook/storybookHandlers"

const handlers = []

initialize({
  onUnhandledRequest: ({ method, url }) => {
    console.info(`Full: ${method} ${url}`)
    if (!url.includes("/api")) {
      console.info(`Passthrough: ${method} ${url}`)
      return passthrough();
    }
  },
}, storyBookHandlers)

const preview: Preview = {
  // decorators: [(storyFn, context) => withConsole()(storyFn)(context)],
  parameters: {
    actions: { argTypesRegex: "^on[A-Z].*" },
    controls: {
      matchers: {
        color: /(background|color)$/i,
        date: /Date$/i,
      },
    },
  },
}

if (typeof global.process === "undefined") {
  const { worker } = require("../tests/mocks/browser")
  worker.start()
}

export default {
  decorators: [withRouter],
  parameters: {
    reactRouter: reactRouterParameters({}),
  },
} satisfies Preview

Any thoughts?

[1] https://github.com/mswjs/msw-storybook-addon#configuring-msw

@aronchick aronchick changed the title Issue with "Undefined Apply" Cannot read properties of undefined (reading 'apply') Feb 13, 2024
@aronchick
Copy link
Author

I don't mean to bother (I know it's open source) but i'm pretty stuck here. Is there a direction I should investigate?

@ibrykov-mdsol
Copy link

It looks like msw-storybook-addon is not compatible with the latest major version of msw. I tried it with version 1.3.2 and it worked just fine.

@ilovett
Copy link

ilovett commented Feb 23, 2024

@aronchick following some of the other issues it looks like there is a beta msw-storybook-addon and some users claiming it works great #121

@aronchick
Copy link
Author

It was just this - i couldn't figure it out. I took it out, and am now just using MSW service worker directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants