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

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

Closed
totsteps opened this issue Apr 18, 2018 · 13 comments
Closed

Comments

@totsteps
Copy link

totsteps commented Apr 18, 2018

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.

@danielduan
Copy link
Member

danielduan commented Apr 18, 2018

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.

@totsteps
Copy link
Author

@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

@danielduan
Copy link
Member

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

@Keraito
Copy link
Contributor

Keraito commented Apr 20, 2018

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

@Keraito
Copy link
Contributor

Keraito commented Apr 20, 2018

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?

@sunilhari
Copy link

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

@Hypnosphi
Copy link
Member

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

@sunilhari
Copy link

@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

@Keraito
Copy link
Contributor

Keraito commented May 5, 2018

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

@Hypnosphi
Copy link
Member

  1. And yarn.lock in the directory where you run getstorybook

@sunilhari
Copy link

sunilhari commented May 5, 2018

@Hypnosphi

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

@Hypnosphi
Copy link
Member

released as 3.4.4

@Chetan11-dev
Copy link

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

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

6 participants