Search code examples
jestjsstorybook

Storyshots jest - Cannot find module '@storybook/react' from 'index.js'


I am trying to incorporate storyshots in my project. I have this jest config:

"moduleFileExtensions": [
  "json",
  "js",
  "jsx"
],

Here is my test file content:

import React from 'react';
import renderer from 'react-test-renderer';
import initStoryshots from '@storybook/addon-storyshots';

import IconCell from './';
initStoryshots({
    framework: 'react'
});
test('iconcell', () => {
    expect(renderer.create(<IconCell size="normal" type="pause" />).toJSON()).toMatchSnapshot();
});

But it throws error:

Cannot find module '@storybook/react' from 'index.js'

The error thrown in node_modules/jest-resolve/build/index.js


Solution

    1. Make sure you install @storybook/react npm module
    2. Check the version of the storybook. Version 2 had the @kadira namespace, but version 3 has a @storybook one. There might be a clash of incompatible base and addon.