storybook: Cannot find module 'react/package.json'

Describe the bug npm run storybook Cannot find module ‘react/package.json’

To Reproduce Steps to reproduce the behavior:

npm init
npx -p @storybook/cli sb init --type react
npm run storybook

Additional context Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 10
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Also need to have react-dom installed as a dev dependency.

In my case, I needed both react and react-dom as devDependencies.

i.e. npm install --save-dev react react-dom

Check if you have added react as part of peer dependencies. It has to be there in dependencies also.

@gaetanmaisse FYI we’re recommending this, which is functionally equivalent to your recommendation, but shorter/simpler:

npx -p @storybook/cli sb init

npx sb init

Hi guys just checked again if anyone facing the error make sure to run :

npm uninstall storybook again install npm install storybook

@xiangxiong running npx -p @storybook/cli sb init --type react let you init Storybook in an already bootstrapped React app, which isn’t your case as you’re only doing npm init.

If you want to bootstrap a React app + Storybook you can do the following:

npx create-react-app <YOUR_APP_NAME>
cd <YOUR_APP_NAME>
npx -p @storybook/cli sb init
npm run storybook

I let you close this issue if my answer solves your problem, otherwise, I let you provide a repro repo.

In my case, with a simple storybook setup, reinstalling node_modules with npm install after deleting the previous node_modules and package-lock.json solved the issue.