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 find module 'react/package.json' #13665

Closed
xiangxiong opened this issue Jan 18, 2021 · 15 comments
Closed

Cannot find module 'react/package.json' #13665

xiangxiong opened this issue Jan 18, 2021 · 15 comments

Comments

@xiangxiong
Copy link

xiangxiong commented Jan 18, 2021

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.

@xiangxiong xiangxiong changed the title react/package.json Cannot find module 'react/package.json' Jan 18, 2021
@gaetanmaisse
Copy link
Member

gaetanmaisse commented Jan 19, 2021

@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.

@shilman
Copy link
Member

shilman commented Feb 22, 2021

@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

@wangJacker
Copy link

The problem remains,use npx sb init

@RyderKishan
Copy link

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

davidharting added a commit to dbt-labs/fishtown-ui that referenced this issue Sep 9, 2021
This gets rid of a typescript warning issue in a dependency, and also nice to keep this up to date.

After upgrading storybook, I ran into an issue where storybook expects React to be installed.

We do not want to ship react with this library, but instead rely on the caller's copy of react.

I noticed that chakra-ui installs react as a dev dependency. I wager that this is for their storybook support as well. See https://github.com/chakra-ui/chakra-ui/blob/8a8b7be6233aa2be717a733bbcf012cfcad29516/packages/button/package.json#L58

Looking at storybook issues, I found storybookjs/storybook#13665 where someone points out that react must be a dev dependency in order for storybook to work properly.
@Jack-Aaron
Copy link

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

@glassdimlygr
Copy link

I can't install react-dom as a dev dependency. First of all, that defeats the point of using preact... because then storybook doesn't use preact. So what would be the point? Finally, I am using nextjs, and it requires the aliasing of react and react-dom like so:

    "react": "npm:@preact/compat",
    "react-dom": "npm:@preact/compat",
    "react-ssr-prepass": "npm:preact-ssr-prepass"

@SiddheshKukade
Copy link

SiddheshKukade commented Jun 10, 2022

Reopen this issue because this it is not fixed
is have also followed the npx sb init command

@SiddheshKukade
Copy link

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

npm uninstall storybook
again install
npm install storybook

@kunalphaltankar
Copy link

kunalphaltankar commented Aug 22, 2022

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

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

@efeharmankaya
Copy link

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.

@viveleroi
Copy link

I'm having this issue on yarn 3.2.4. I tried installing sb via npx sb@next init --builder=vite. I was hoping to use this because storybook 6 has some deps that break on node 17+.

I think the issue here is yarn 3... if something is actually looking for the file (Cannot find module '@storybook/react/package.json') it's not going to be there because yarn 3 uses the new plug'n'play system.

@mtrabelsi
Copy link

building software that no one will use, react-dom is missing and storybook team does not give a *** adding this tiny step

@shilman
Copy link
Member

shilman commented Nov 10, 2022

@viveleroi did you try adding a dev dependency on @storybook/react to your project?

@viveleroi
Copy link

viveleroi commented Nov 10, 2022 via email

@davidmnoll
Copy link

I'm having this issue on an HTML based project. i don't want to have to install react... is that possible?

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

No branches or pull requests