question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'STORYBOOK_HOOKS_CONTEXT' of undefined

See original GitHub issue

Describe the bug When running initStoryshots from import initStoryshots from "@storybook/addon-storyshots" an error occurs when storyshots starts.

Code snippets

Storyshot code:

import initStoryshots from "@storybook/addon-storyshots"

describe("storybook tests", () => {
  initStoryshots({
    configPath: "./storybook",
    framework: "react-native"
  })
})

Error from console:

 ● storybook tests › Storyshots › Header › Behavior

    TypeError: Cannot read property 'STORYBOOK_HOOKS_CONTEXT' of undefined

      at node_modules/@storybook/addons/dist/hooks.js:236:38
      at node_modules/@storybook/client-api/dist/client_api.js:129:14
      at node_modules/@storybook/addons/dist/hooks.js:266:20
      at Object.storyFn (node_modules/@storybook/client-api/dist/story_store.js:363:30)
      at getRenderedTree (node_modules/@storybook/addon-storyshots/dist/frameworks/react/renderTree.js:22:28)
      at node_modules/@storybook/addon-storyshots/dist/test-bodies.js:21:18
      at Object.<anonymous> (node_modules/@storybook/addon-storyshots/dist/api/snapshotsTestsTemplate.js:44:47)

System:

Environment Info:

  System:
    OS: macOS 10.15
    CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  Binaries:
    Node: 12.10.0 - /usr/local/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.11.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 76.0.3809.132
    Safari: 13.0.1
  npmPackages:
    @storybook/addon-storyshots: ^5.1.11 => 5.2.0 
    @storybook/react-native: ^5.1.11 => 5.2.0 
    @storybook/theming: ^5.1.11 => 5.2.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
loic-lopezcommented, Sep 19, 2019

@vladstart1 I have imported merge function from lodash

Your error:

Invalid variable access: merge

You can do:

jest.mock("global", () => Object.assign(global, { window: { STORYBOOK_HOOKS_CONTEXT: "" } }));
0reactions
shilmancommented, Oct 7, 2019

Yee-haw!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.2.2 containing PR #8163 that references this issue. Upgrade today to try it out!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'key' of undefined storybook react
after this I got another error for Router and I solve it by using StoryRouter from storybook-react-router. Thanks again :) – Aidayg24. Jun...
Read more >
storybook cannot read properties of undefined ... - You.com
The TypeError: Cannot read properties of undefined (reading 'type') exception occurs in storybook when one defines the argTypes in the default export object ......
Read more >
Storyshots Addon | Storybook: Frontend workshop for UI ...
jest/register-context.js : import registerRequireContextHook from 'babel-plugin-require-context-hook/register'; ...
Read more >
@storybook/addon-storyshots - npm
Take a code snapshot of every story automatically with Jest. Latest version: 6.5.15, last published: 4 days ago.
Read more >
How to Read React Errors (fix 'Cannot read property of ...
This error usually means you're trying to use .map on an array, but that array isn't defined yet. That's often because the array...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found