The Wayback Machine - https://web.archive.org/web/20200605194112/https://github.com/storybookjs/storybook/issues/9243
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

TypeError: Cannot set property 'storybook' of undefined from npx -p @storybook/cli sb init #9243

Open
levelingup opened this issue Dec 24, 2019 · 9 comments

Comments

@levelingup
Copy link

@levelingup levelingup commented Dec 24, 2019

I tried to follow the initial steps from here: https://www.learnstorybook.com/intro-to-storybook/react/en/get-started/

running:

npx create-react-app taskbox
cd taskbox

Then when I ran:
npx -p @storybook/cli sb init

I get the error TypeError: Cannot set property 'storybook' of undefined

This is the full message in my terminal:

 sb init - the simplest way to add a storybook to your project. 

 • Detecting project type. ✓
 • Adding storybook support to your "Create React App" based project
     TypeError: Cannot set property 'storybook' of undefined
    at default (/Users/levelingup/.npm/_npx/2358/lib/node_modules/@storybook/cli/generators/REACT_SCRIPTS/index.js:29:33)
    at process._tickCallback (internal/process/next_tick.js:68:7)

running npx --version: 6.9.0

@shilman
Copy link
Member

@shilman shilman commented Dec 25, 2019

Are you sure you're running that inside the taskbox directory?

@levelingup
Copy link
Author

@levelingup levelingup commented Dec 25, 2019

Are you sure you're running that inside the taskbox directory?

Yup, i was in the directory when I ran npx -p @storybook/cli sb init

@shilman
Copy link
Member

@shilman shilman commented Dec 25, 2019

The line that errored is trying to add something to the scripts field of package.json. Can you check to see if your package.json has a scripts field? Mine does when I try to repro.

@levelingup
Copy link
Author

@levelingup levelingup commented Dec 25, 2019

No scripts field. Only thing in my package.json:

{
  "name": "taskbox",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "3.3.0"
  }
}
@BanlyTong
Copy link

@BanlyTong BanlyTong commented Dec 26, 2019

I encountered the same problem.
It caused because I installed create-react-app globally, so npx didn't use the latest version of cra.

The problem was solved after I uninstalled the global create-react-app package.
And here is how to do it.

@shilman shilman added bug and removed question / support labels Dec 26, 2019
@shilman
Copy link
Member

@shilman shilman commented Dec 26, 2019

I think the CLI should be smart enough to add a scripts section to your package.json if there isn't one. Great first issue if somebody wants to take it!

@Manish-Giri
Copy link

@Manish-Giri Manish-Giri commented Dec 28, 2019

Hello, I would like to give this a shot..

@emileber
Copy link

@emileber emileber commented Jan 9, 2020

@Manish-Giri While you're at it, it would be great if the CLI failed gracefully when there is no package.json at all. While really uncommon, right now, if crashes with the following error.

TypeError: Cannot create property 'dependencies' on boolean 'false'

I think it comes from the following lines:

  const packageJson = await retrievePackageJson();
  // missing a check here and a helpful error message.
  packageJson.dependencies = packageJson.dependencies || {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6 participants
@shilman @levelingup @emileber @Manish-Giri @BanlyTong and others
You can’t perform that action at this time.