Storybook: [storybook/cli] Fails if package.json at /home/user has no license field.

Created on 18 Apr 2018  Â·  13Comments  Â·  Source: storybookjs/storybook

Summary

storybook/cli gives an error when initiating a repo with $ getstorybook.

Here's the error:

:~/blog/taskbox$ npx -p @storybook/cli getstorybook
  npx: installed 312 in 22.043s

  getstorybook - the simplest way to add a storybook to your project. 

  • Detecting project type. ✓
  • Adding storybook support to your "Create React App" based project
      ../../package.json: No license field

      ../../package.json: No license field

      ../../package.json: No license field

Seems like getstorybook fails if package.json at /home/user does not have a licese field.

Steps to reproduce

  1. sudo npm i -g @storybook/cli
  2. getstorybook

Please specify which version of Storybook and optionally any affected addons that you're running

  • storybook/cli: 3.4.2
  • Addons: none

Solution

It works fine if I add a license field in package.json at home dir.

bug cli help wanted

Most helpful comment

@Hypnosphi

Sorry some way it was using npm.Yeah the issue still exist.yarn.lock was not there

All 13 comments

I believe this is a warning thrown by npm.

If you do npm install @storybook/react --save for example in the same directory, you should get the same warning.

Does this prevent getstorybook from completing the install?

I personally don't think we should get into the business of catching npm warnings as there are many more such as No repository field, No description. The message is clear and the error issimple enough to fix.

@danielduan thanks.

Does this prevent getstorybook from completing the install?

Yes it does prevent getstorybook from completing the install.

Content of package.json

  • Before license field.
{
  "dependencies": {
    "create-react-app": "^1.5.2",
    "gatsby": "^1.9.240",
    "gatsby-cli": "^1.1.48",
    "global": "^4.3.2",
    "roast-my-deps": "^2.0.0"
  }
}
 ```

* After ```license``` field.

{
"license": "MIT",
"dependencies": {
"create-react-app": "^1.5.2",
"gatsby": "^1.9.240",
"gatsby-cli": "^1.1.48",
"global": "^4.3.2",
"roast-my-deps": "^2.0.0"
}
}
```

Screenshot of terminal before and after license field.

story

If you or someone would like to open a PR to fix this, please do.

I would like to give this a try. I assume the intended behaviour is to install regardless of a license field, @danielduan?

I'm not quite sure how to tackle this problem.

After mimicking error locally, I looked into the code and got to the point where https://github.com/storybooks/storybook/blob/master/lib/cli/bin/generate.js#L98 is called, which leads me to https://github.com/storybooks/storybook/blob/master/lib/cli/lib/helpers.js#L86. That should be the last line logged, as there is no red or green chalk added before the repeated No license field. I assume it exits on https://github.com/storybooks/storybook/blob/bc6c66d1784cb027c6e4b924e8eb7c2523d5423b/lib/cli/bin/generate.js#L181, but I can't quite figure out where it catches the exception from.

Am I looking at the wrong place or missing something?

@danielduan

It seems that here it goes to the error if the license is not specified.
https://github.com/storybooks/storybook/blob/master/lib/cli/lib/latest_version.js#L8
Can u guide me to fix this issue??

@Keraito if this finding helps you to fix ,feel free to.

That’s weird that it checks package.json in your home directory. Unless you have no package.json in the directory where you run getstorybook. You might want to create it first using npm init

@Keraito @Hypnosphi

Did this issue get fixed.I was trying today on 3.4.3version of the cli and this went through with out any errors.I understand that @Keraito code is not merged.But the issue is not there anymore.

Please confirm

@sunilhari can you check whether

  1. There is a package.json at the direct path from your home to your project?
  2. It has no license field?
  3. You have yarn installed?
  1. And yarn.lock in the directory where you run getstorybook

@Hypnosphi

Sorry some way it was using npm.Yeah the issue still exist.yarn.lock was not there

released as 3.4.4

It fixed my problem
sudo npm i -g @storybook/cli
sb init

Was this page helpful?
0 / 5 - 0 ratings