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 init in a new project #26553

Open
pavi2410 opened this issue Mar 18, 2024 · 59 comments · May be fixed by #29577
Open

Cannot init in a new project #26553

pavi2410 opened this issue Mar 18, 2024 · 59 comments · May be fixed by #29577

Comments

@pavi2410
Copy link

pavi2410 commented Mar 18, 2024

Describe the bug

I am trying to install Storybook in a new project. But when I run npx storybook@latest init, it says "Error: Unable to find versions of @storybook/cli using npm"

To Reproduce

Run npx storybook@latest init

System

Storybook Environment Info:
 
   System:
     OS: Linux 6.5 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
     CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
     Shell: 5.1.16 - /bin/bash
   Browsers:
     Chrome: 122.0.6261.128

Additional context

 Error: Unable to find versions of @storybook/cli using npm
     at NPMProxy.runGetVersions (/home/pavitra/.npm/_npx/6fe9a9991b157df1/node_modules/@storybook/core-common/dist/index.js:37:639)
     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
     at async doInitiate (/home/pavitra/.npm/_npx/6fe9a9991b157df1/node_modules/@storybook/cli/dist/generate.js:146:997)
     at async withTelemetry (/home/pavitra/.npm/_npx/6fe9a9991b157df1/node_modules/@storybook/core-server/dist/index.js:28:3579)
     at async initiate (/home/pavitra/.npm/_npx/6fe9a9991b157df1/node_modules/@storybook/cli/dist/generate.js:180:250)
@Kenzo-Wada
Copy link

I think you should npm install @storybook/cli first.

@pavi2410
Copy link
Author

I think you should npm install @storybook/cli first.

npx installs the CLI if it isn't already available. Also, nowhere in the getting started guide it is mentioned that the CLI needs to be installed separately before.

@shilman
Copy link
Member

shilman commented Mar 18, 2024

Have you tried clearing your npm cache and running again?

@pavitra-infocusp
Copy link

Have you tried clearing your npm cache and running again?

Yes!

❯ npm cache clean --force
npm WARN using --force Recommended protections disabled.

❯ npx storybook@latest init
Error: Unable to find versions of @storybook/cli using npm
    at NPMProxy.runGetVersions (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/core-common/dist/index.js:37:639)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doInitiate (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/cli/dist/generate.js:146:997)
    at async withTelemetry (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/core-server/dist/index.js:28:3579)
    at async initiate (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/cli/dist/generate.js:180:250)

@vanessayuenn
Copy link
Contributor

Out of curiosity, does this happen if you try to run npx storybook@latest init in an empty directory?

@pavi2410
Copy link
Author

Out of curiosity, does this happen if you try to run npx storybook@latest init in an empty directory?

Yes, I even tried that earlier.

@vanessayuenn
Copy link
Contributor

This is really strange. Does this command npm info @storybook/cli version --json execute successfully?

@pavitra-infocusp
Copy link

This is really strange. Does this command npm info @storybook/cli version --json execute successfully?

Yes, it does

❯ npm info @storybook/cli version --json
"8.0.2"

@pavitra-infocusp
Copy link

Tried it again with 8.0.2; didn't work

❯ npx storybook@latest init
Need to install the following packages:
storybook@8.0.2
Ok to proceed? (y) y
Error: Unable to find versions of @storybook/cli using npm
    at NPMProxy.runGetVersions (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/core-common/dist/index.js:37:639)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doInitiate (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/cli/dist/generate.js:146:997)
    at async withTelemetry (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/core-server/dist/index.js:28:3579)
    at async initiate (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/cli/dist/generate.js:180:250)

Copy link
Contributor

Hi there! Thank you for opening this issue, but it has been marked as stale because we need more information to move forward. Could you please provide us with the requested reproduction or additional information that could help us better understand the problem? We'd love to resolve this issue, but we can't do it without your help!

@github-actions github-actions bot added the Stale label Apr 11, 2024
Copy link
Contributor

I'm afraid we need to close this issue for now, since we can't take any action without the requested reproduction or additional information. But please don't hesitate to open a new issue if the problem persists – we're always happy to help. Thanks so much for your understanding.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
@pavitra-infocusp
Copy link

pavitra-infocusp commented Apr 29, 2024

Thought I should give it a try again and ran into this issue again.

This time I tried to debug what's the case. It seems that the execCommand function at this line returns an empty string. The command execution went well. The console logs below proves that.

❯ npx storybook init
"8.0.9"                        <--- stdio inherit passed to execCommand
{ commandResult: '' }          <--- It should have been "8.0.9"
Unexpected end of JSON input   <--- json parsing on empty string
Error: Unable to find versions of @storybook/cli using npm

@pavitra-infocusp
Copy link

@shilman Can you please reopen this issue?

@pavitra-infocusp
Copy link

So, I went deep further, and learnt that the stdout from the command is undefined, which is very strange as neither stderr is defined.

{
  commandResult: {
    command: 'npm info @storybook/cli version --json',
    escapedCommand: 'npm info "@storybook/cli" version --json',
    exitCode: 0,
    stdout: undefined,
    stderr: undefined,
    all: undefined,
    failed: false,
    timedOut: false,
    isCanceled: false,
    killed: false
  }
}

@pavitra-infocusp
Copy link

looks like something is wrong with execa.

import {execa} from 'execa';

const commandResult = await execa('npm', ['info', '@storybook/cli', 'version', '--json']);
console.log(commandResult);
❯ node testexec.js 
{
  command: 'npm info @storybook/cli version --json',
  escapedCommand: 'npm info "@storybook/cli" version --json',
  exitCode: 0,
  stdout: '',
  stderr: '',
  all: undefined,
  failed: false,
  timedOut: false,
  isCanceled: false,
  killed: false
}

@shilman
Copy link
Member

shilman commented Apr 29, 2024

@pavitra-infocusp re-opened. so i guess we wait for the resolution in execa? thanks so much for digging in on this. 🙏

@shilman shilman removed the Stale label Apr 29, 2024
@ehmicky
Copy link

ehmicky commented Apr 29, 2024

👋 I am Execa's co-maintainer.

From the look of it, I do not think there is a bug with Execa there, but the issue at sindresorhus/execa#995 can track this.

In terms of calling Execa in Storybook, I would recommend replacing execaCommand() with execa() instead. execaCommand() is intended for REPL, not programmatic usage. This documentation explains it. The current usage in Storybook might not be escaping arguments properly due to this.

More details: the shell: true option executes the command and its argument as a single string, with the shell interpreting it. The execaCommand() splits the input string into a command and an arguments array using spaces as delimiters. And Storybook joins the command and the arguments array into a string. So right now, this looks this:

runCommand({command: 'npm', arguments: ['install', 'example with space']});
-> execaCommand('npm install example with space', {shell: true});
-> execa('npm', ['install', 'example with space'], {shell: true});
-> child_process.spawn('npm', ['install', 'example with space'], {shell: true});
-> (on Unix) bash -c "npm install example with space"
   (on Windows) cmd /d /s /c "npm install example with space"

As you can see, the execaCommand()'s parsing is not really needed there, and execa() could be called directly instead.

The shell: true option is usually problematic, as it prevents proper escaping (as you see from the above example with spaces, which end up not being quoted), which could look to command injection. However, npm and yarn are weird, and might requires being running in a shell, depending on your case.

const commandResult = await execaCommand([command, ...args].join(' '), {
cwd: cwd ?? this.cwd,
stdio: stdio ?? 'pipe',
encoding: 'utf-8',
shell: true,
cleanup: true,
env,
...execaOptions,
});

@shilman
Copy link
Member

shilman commented Apr 29, 2024

@ehmicky Thanks so much for helping out here (and for maintaining Execa -- you rock!!!). I'm not sure whether we are on Execa v5 out of laziness or there's something specific that's holding us back. I'll check with the team and we'll try to get it upgraded. Hopefully @pavitra-infocusp or one of the other folks who experienced this issue can confirm the fix. 🙏

@jeffijoe
Copy link

jeffijoe commented Jun 25, 2024

I've been trying with pnpm and get the same error.

Node: 20.12.1
PNPM: 9.4.0

❯ pnpm dlx storybook@latest init
Error: Unable to find versions of @storybook/cli using pnpm
    at PNPMProxy.runGetVersions (/Users/jeff.hansen/Library/Caches/pnpm/dlx/unbkmcv47bmd3k4heaisxlpgg4/1904fecd90e-4f0e/node_modules/.pnpm/@storybook+core-common@8.1.10_prettier@3.3.2/node_modules/@storybook/core-common/dist/index.js:39:638)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doInitiate (/Users/jeff.hansen/Library/Caches/pnpm/dlx/unbkmcv47bmd3k4heaisxlpgg4/1904fecd90e-4f0e/node_modules/.pnpm/@storybook+cli@8.1.10_@babel+preset-env@7.24.7_@babel+core@7.24.7__react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@storybook/cli/dist/generate.js:146:992)
    at async withTelemetry (/Users/jeff.hansen/Library/Caches/pnpm/dlx/unbkmcv47bmd3k4heaisxlpgg4/1904fecd90e-4f0e/node_modules/.pnpm/@storybook+core-server@8.1.10_prettier@3.3.2_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@storybook/core-server/dist/index.js:40:3599)
    at async initiate (/Users/jeff.hansen/Library/Caches/pnpm/dlx/unbkmcv47bmd3k4heaisxlpgg4/1904fecd90e-4f0e/node_modules/.pnpm/@storybook+cli@8.1.10_@babel+preset-env@7.24.7_@babel+core@7.24.7__react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@storybook/cli/dist/generate.js:180:214)

EDIT: Despite not even using npm, upgrading to 10.8.1 made it work.

@bcraun
Copy link

bcraun commented Jun 25, 2024

Confirming upgrade to npm 10.8.1 resolved the issue for me, as well. Thank you @yannbf!

$ npm i -g npm@10.8.1
$ npx storybook@latest init

@anguspiv
Copy link

anguspiv commented Jun 26, 2024

Confirming, upgrading npm to 10.8.1 resolved the issue when using pnpm.

> nvm install 20
> node --version
v20.15.0
>  npm --version
10.8.1
> pnpm dlx storybook@latest init

@lb-
Copy link

lb- commented Jun 26, 2024

Updating npm also fixed the issue for me. Thank you team.

@vanessayuenn
Copy link
Contributor

Looks like this has been resolved then! Thanks everyone for confirming the fix.

@github-project-automation github-project-automation bot moved this from Blocked to Done in Core Team Projects Jul 1, 2024
@pavitra-infocusp
Copy link

pavitra-infocusp commented Jul 2, 2024

I don't know why this still doesn't work for me :(

I just started a new React + Vite project and I am still not able to init Storybook.

❯ npx storybook@latest init
Need to install the following packages:
storybook@8.1.11
Ok to proceed? (y) y

npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated rimraf@2.6.3: Rimraf versions prior to v4 are no longer supported
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
(node:143516) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Error: Unable to find versions of @storybook/cli using npm
    at NPMProxy.runGetVersions (/home/pavitra/.npm/_npx/76a56df03ee7b47f/node_modules/@storybook/core-common/dist/index.js:37:639)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doInitiate (/home/pavitra/.npm/_npx/76a56df03ee7b47f/node_modules/@storybook/cli/dist/generate.js:146:992)
    at async withTelemetry (/home/pavitra/.npm/_npx/76a56df03ee7b47f/node_modules/@storybook/core-server/dist/index.js:40:3599)
    at async initiate (/home/pavitra/.npm/_npx/76a56df03ee7b47f/node_modules/@storybook/cli/dist/generate.js:180:214)
❯ npx storybook@latest -V
8.1.11

❯ node -v
v22.1.0

❯ npm -v
10.8.1

@bcraun
Copy link

bcraun commented Jul 2, 2024

@pavitra-infocusp , last week Storybook 8.1.10 was latest, but other than that my npm and node versions are the same as yours. It's a stretch, but have you tried installing 8.1.10?

@pavitra-infocusp
Copy link

Nope, 8.1.10 doesn't work either :(

❯ npx storybook@8.1.10 init
Need to install the following packages:
storybook@8.1.10
Ok to proceed? (y) y

npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated rimraf@2.6.3: Rimraf versions prior to v4 are no longer supported
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
(node:192751) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Error: Unable to find versions of @storybook/cli using npm
    at NPMProxy.runGetVersions (/home/pavitra/.npm/_npx/4862a5c4b3784c7e/node_modules/@storybook/core-common/dist/index.js:37:639)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doInitiate (/home/pavitra/.npm/_npx/4862a5c4b3784c7e/node_modules/@storybook/cli/dist/generate.js:146:992)
    at async withTelemetry (/home/pavitra/.npm/_npx/4862a5c4b3784c7e/node_modules/@storybook/core-server/dist/index.js:40:3599)
    at async initiate (/home/pavitra/.npm/_npx/4862a5c4b3784c7e/node_modules/@storybook/cli/dist/generate.js:180:214)

@pavitra-infocusp
Copy link

I tried using the next tag, resulting in the same error.

❯ npx storybook@next init
Need to install the following packages:
storybook@8.2.0-alpha.10
Ok to proceed? (y) y

npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated rimraf@2.6.3: Rimraf versions prior to v4 are no longer supported
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
(node:212042) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Error: Unable to find versions of @storybook/cli using npm
    at NPMProxy.runGetVersions (/home/pavitra/.npm/_npx/eb8bf615e50a412a/node_modules/@storybook/core-common/dist/index.js:37:639)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doInitiate (/home/pavitra/.npm/_npx/eb8bf615e50a412a/node_modules/@storybook/cli/dist/generate.js:146:992)
    at async withTelemetry (/home/pavitra/.npm/_npx/eb8bf615e50a412a/node_modules/@storybook/core-server/dist/index.js:40:3599)
    at async initiate (/home/pavitra/.npm/_npx/eb8bf615e50a412a/node_modules/@storybook/cli/dist/generate.js:180:214)

@pavitra-infocusp
Copy link

pavitra-infocusp commented Jul 11, 2024

I just tried again with 8.2.1 and got a fancy error message this time. No difference in the error though.

❯ npx storybook@latest init
Need to install the following packages:
storybook@8.2.1
Ok to proceed? (y) y

npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated rimraf@2.6.3: Rimraf versions prior to v4 are no longer supported
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
SB_CLI_0001 (FindPackageVersionsError): Unable to find versions of "storybook" using NPM
Reason: Error: Command failed with exit code 1: npm info storybook version --json
    at QJ.runGetVersions (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/core/dist/common/index.cjs:153538:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doInitiate (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/storybook/dist/generate.cjs:157:982)
    at async withTelemetry (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/core/dist/core-server/index.cjs:188662:12)
    at async initiate (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/storybook/dist/generate.cjs:191:214) {
  category: 'CLI',
  code: 1,
  data: {
    error: Error: Command failed with exit code 1: npm info storybook version --json
        at makeError (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/core/dist/common/index.cjs:152294:67)
        at handlePromise (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/core/dist/common/index.cjs:152914:15)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async QJ.executeCommand (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/core/dist/common/index.cjs:153365:15)
        at async QJ.runGetVersions (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/core/dist/common/index.cjs:153530:15)
        at async doInitiate (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/storybook/dist/generate.cjs:157:982)
        at async withTelemetry (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/@storybook/core/dist/core-server/index.cjs:188662:12)
        at async initiate (/home/pavitra/.npm/_npx/bc7e1e37fcb46ffc/node_modules/storybook/dist/generate.cjs:191:214) {
      shortMessage: 'Command failed with exit code 1: npm info storybook version --json',
      command: 'npm info storybook version --json',
      escapedCommand: 'npm info storybook version --json',
      exitCode: 1,
      signal: undefined,
      signalDescription: undefined,
      stdout: '',
      stderr: '',
      cwd: '/home/pavitra/Projects/<redacted>',
      failed: true,
      timedOut: false,
      isCanceled: false,
      killed: false
    },
    packageManager: 'NPM',
    packageName: 'storybook'
  },
  documentation: false,
  fromStorybook: true
}

attention => Storybook now collects completely anonymous telemetry regarding usage.
This information is used to shape Storybook's roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://storybook.js.org/telemetry

@pavitra-infocusp
Copy link

I'll try to fix and send a PR.

@edmacovaz
Copy link

Still getting the error on

Node: 22.0.9
npm: 10.8.3
Storybook: 8.3.3

SB_CLI_0001 (FindPackageVersionsError): Unable to find versions of "storybook" using NPM
Reason: SyntaxError: Unexpected non-whitespace character after JSON at position 3
    at _F.runGetVersions (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/@storybook/core/dist/common/index.cjs:142627:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doInitiate (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/create-storybook/dist/bin/index.cjs:85:995)
    at async withTelemetry (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/@storybook/core/dist/core-server/index.cjs:47080:12)
    at async initiate (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/create-storybook/dist/bin/index.cjs:119:214) {
  data: {
    error: SyntaxError: Unexpected non-whitespace character after JSON at position 3
        at JSON.parse (<anonymous>)
        at _F.runGetVersions (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/@storybook/core/dist/common/index.cjs:142622:20)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async doInitiate (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/create-storybook/dist/bin/index.cjs:85:995)
        at async withTelemetry (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/@storybook/core/dist/core-server/index.cjs:47080:12)
        at async initiate (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/create-storybook/dist/bin/index.cjs:119:214),
    packageManager: 'NPM',
    packageName: 'storybook'
  },
  fromStorybook: true,
  category: 'CLI',
  documentation: false,
  code: 1
}

@rseverinop
Copy link

rseverinop commented Sep 29, 2024

Still getting the error on

Node: 22.0.9 npm: 10.8.3 Storybook: 8.3.3

SB_CLI_0001 (FindPackageVersionsError): Unable to find versions of "storybook" using NPM
Reason: SyntaxError: Unexpected non-whitespace character after JSON at position 3
    at _F.runGetVersions (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/@storybook/core/dist/common/index.cjs:142627:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doInitiate (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/create-storybook/dist/bin/index.cjs:85:995)
    at async withTelemetry (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/@storybook/core/dist/core-server/index.cjs:47080:12)
    at async initiate (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/create-storybook/dist/bin/index.cjs:119:214) {
  data: {
    error: SyntaxError: Unexpected non-whitespace character after JSON at position 3
        at JSON.parse (<anonymous>)
        at _F.runGetVersions (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/@storybook/core/dist/common/index.cjs:142622:20)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async doInitiate (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/create-storybook/dist/bin/index.cjs:85:995)
        at async withTelemetry (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/@storybook/core/dist/core-server/index.cjs:47080:12)
        at async initiate (/Users/edmacovaz/.npm/_npx/3158839f1cfed546/node_modules/create-storybook/dist/bin/index.cjs:119:214),
    packageManager: 'NPM',
    packageName: 'storybook'
  },
  fromStorybook: true,
  category: 'CLI',
  documentation: false,
  code: 1
}

I have the same problem, and I can't find any resourse to fix this problem.

node version: v20.17
npm: 10.8.3
Storybook: 8.3.3

@abolfazlcodes
Copy link

Has anyone found a solution?

@acastle-optimist
Copy link

also getting this issue, again.
node 21..5.0
npm 10.8.1

@JReinhold JReinhold reopened this Oct 22, 2024
@JReinhold
Copy link
Contributor

@vanessayuenn appears that this is still an issue for some users, even on newer versions.

@ghengeveld
Copy link
Member

This might be resolved by upgrading Execa and replacing execaCommand with execa, since execaCommand is deprecated and should generally be avoided.

@shilman shilman moved this from Done to Empathy Backlog in Core Team Projects Oct 23, 2024
@johnmanko
Copy link

johnmanko commented Oct 25, 2024

In an empty directory, npx storybook@latest init with Next.js (TS) fails to install (it just sits there).

❯ npx storybook@latest init
╭──────────────────────────────────────────────────────╮
│                                                      │
│   Adding Storybook version 8.3.6 to your project..   │
│                                                      │
╰──────────────────────────────────────────────────────╯
╔ 🔎 Empty directory detected ══════════════════════════════════════════════════════════════════════╗
║                                                                                                   ║
║   Would you like to generate a new project from the following list?                               ║
║                                                                                                   ║
║   Note:                                                                                           ║
║   Storybook supports many more frameworks and bundlers than listed below. If you don't see your   ║
║   preferred setup, you can still generate a project then rerun this command to add Storybook.     ║
║                                                                                                   ║
║   Press ^C at any time to quit.                                                                   ║
║                                                                                                   ║
╚═══════════════════════════════════════════════════════════════════════════════════════════════════╝

✔ Choose a project template › Next.js (TS)

Creating a new "Next.js (TS)" project with npm...

I end up having to kill the process. When I do, there are only three files created in .cache/storybook/default/dev-server.

Choosing React + Vite (TS) completes:

❯ npx storybook@latest init
╭──────────────────────────────────────────────────────╮
│                                                      │
│   Adding Storybook version 8.3.6 to your project..   │
│                                                      │
╰──────────────────────────────────────────────────────╯
╔ 🔎 Empty directory detected ══════════════════════════════════════════════════════════════════════╗
║                                                                                                   ║
║   Would you like to generate a new project from the following list?                               ║
║                                                                                                   ║
║   Note:                                                                                           ║
║   Storybook supports many more frameworks and bundlers than listed below. If you don't see your   ║
║   preferred setup, you can still generate a project then rerun this command to add Storybook.     ║
║                                                                                                   ║
║   Press ^C at any time to quit.                                                                   ║
║                                                                                                   ║
╚═══════════════════════════════════════════════════════════════════════════════════════════════════╝

✔ Choose a project template › React + Vite (TS)

Creating a new "React + Vite (TS)" project with npm...

╔ ✅ Success! ═══════════════════════════════════════════════════╗
║                                                                ║
║   "React + Vite (TS)" project with npm created successfully!   ║
║                                                                ║
║   Continuing with Storybook installation...                    ║
║                                                                ║
╚════════════════════════════════════════════════════════════════╝

 • Detecting project type
attention => Storybook now collects completely anonymous telemetry regarding usage.
This information is used to shape Storybook's roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://storybook.js.org/telemetry

. ✓
Installing dependencies...


added 182 packages, and audited 183 packages in 16s

41 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
 • Adding Storybook support to your "React" app • Detected Vite project. Setting builder to Vite. ✓

  ✔ Getting the correct version of 10 packages
    Configuring eslint-plugin-storybook in your package.json
  ✔ Installing Storybook dependencies
. ✓
Installing dependencies...


up to date, audited 456 packages in 777ms

124 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
╭──────────────────────────────────────────────────────────────────────────────╮
│                                                                              │
│   Storybook was successfully installed in your project! 🎉                   │
│   To run Storybook manually, run npm run storybook. CTRL+C to stop.          │
│                                                                              │
│   Wanna know more about Storybook? Check out https://storybook.js.org/       │
│   Having trouble or want to chat? Join us at https://discord.gg/storybook/   │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

Running Storybook

.....

❯ zsh --version
zsh --version
zsh 5.9 (x86_64-ubuntu-linux-gnu)

❯ uname -a
Linux xxxxxx 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

❯ node -v
v22.9.0

❯ npm -v
10.8.3

@okaeiz
Copy link

okaeiz commented Nov 4, 2024

I still have this issue. What should I do?

@valentinpalkovic
Copy link
Contributor

Can you all please try out the latest version of storybook (8.4.0) by running npx storybook@latest init in an empty directory?

@okaeiz
Copy link

okaeiz commented Nov 4, 2024

Can you all please try out the latest version of storybook (8.4.0) by running npx storybook@latest init in an empty directory?

Initializing Storybook in a fresh environment works fine. I ran the command in an empty directory and the wizard showed up but when I try to add Storybook to an existing React project, it fails.

@valentinpalkovic
Copy link
Contributor

@okaeiz Can you provide a repo where Storybook fails to initialize?

@johnrcui
Copy link

johnrcui commented Nov 8, 2024

I've been having the same issue and came here to find a solution, but since none have been posted, I just decided to look into it myself.

The problem seems to stem from a command executed that runs npm info storybook version --json and parses it as JSON. This command currently returns 8.4.2 (which is not a valid JSON and throws an error). Note that if the latest version was didn't have a build version such as 8.4 it would have passed since this is valid JSON (number).

Here's the specific area that fails in /core/src/common/js-package-manager/NPMProxy.ts#L238-L264 along with the suggested fix

  protected async runGetVersions<T extends boolean>(
    packageName: string,
    fetchAllVersions: T
  ): Promise<T extends true ? string[] : string> {
-    const args = [fetchAllVersions ? 'versions' : 'version', '--json'];
+    const args = [fetchAllVersions ? 'versions --json' : 'version'];
    try {
      const commandResult = await this.executeCommand({
        command: 'npm',
        args: ['info', packageName, ...args],
      });

-      const parsedOutput = JSON.parse(commandResult);
+      const parsedOutput = fetchAllVersions ? JSON.parse(commandResult) : commandResult;

      if (parsedOutput.error?.summary) {
        // this will be handled in the catch block below
        throw parsedOutput.error.summary;
      }

      return parsedOutput;
    } catch (error) {
      throw new FindPackageVersionsError({
        error,
        packageManager: 'NPM',
        packageName,
      });
    }
  }

The same command in pnpm also returns the same semantic version which when parsed as JSON will also fail. I'll submit a PR for this unless someone else get to it before I do.


EDIT: Looks like the root cause is related to npm. Older versions would output npm info storybook version --json as "8.4.2" (quoted string)

@johnrcui johnrcui linked a pull request Nov 8, 2024 that will close this issue
8 tasks
@aaronshenhao
Copy link

aaronshenhao commented Nov 21, 2024

I found that a lot of the npx commands, including init, does not work with Node 22. It worked after I downgraded Node to version 20. I made an issue here (now closed): #29673 (reproducible in Docker).

I noticed that most people here are using Node 22. The error I had is slightly different though (no error, just hangs indefinitely).

@amunrarara
Copy link

amunrarara commented Dec 8, 2024

I'm also encountering this issue. I have a Deno 2.0, Vite, React, SWC project

I've now run three different commands:

yarn dlx storybook@latest init using both Node v18.20.5 and v20.10.0 produces the following:

yarn dlx storybook@latest init

➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 1s 108ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ esbuild@npm:0.24.0 must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 0s 754ms
➤ YN0000: Done with warnings in 1s 897ms

SB_CLI_0001 (FindPackageVersionsError): Unable to find versions of "storybook" using Yarn Berry
Reason: Error: Command failed with exit code 1: yarn npm info storybook --fields version --json
error Couldn't find a package.json file in "/Users/aceaspades/Projects/conduit/projects/conduit-market-client"
yarn run v1.22.22
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
at gi.runGetVersions (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/common/index.cjs:19965:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async doInitiate (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/create-storybook/dist/bin/index.cjs:89:1000)
at async withTelemetry (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/core-server/index.cjs:35757:12)
at async initiate (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/create-storybook/dist/bin/index.cjs:127:214) {
data: {
error: Error: Command failed with exit code 1: yarn npm info storybook --fields version --json
error Couldn't find a package.json file in "/Users/aceaspades/Projects/conduit/projects/conduit-market-client"
yarn run v1.22.22
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
at makeError (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/common/index.cjs:18141:67)
at handlePromise (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/common/index.cjs:18759:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async gi.executeCommand (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/common/index.cjs:19205:15)
at async gi.runGetVersions (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/common/index.cjs:19959:15)
at async doInitiate (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/create-storybook/dist/bin/index.cjs:89:1000)
at async withTelemetry (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/core-server/index.cjs:35757:12)
at async initiate (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/create-storybook/dist/bin/index.cjs:127:214) {
shortMessage: 'Command failed with exit code 1: yarn npm info storybook --fields version --json',
command: 'yarn npm info storybook --fields version --json',
escapedCommand: 'yarn npm info storybook --fields version --json',
exitCode: 1,
signal: undefined,
signalDescription: undefined,
stdout: 'yarn run v1.22.22\n' +
'info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.',
stderr: error Couldn't find a package.json file in "/Users/aceaspades/Projects/conduit/projects/conduit-market-client",
cwd: '/Users/aceaspades/Projects/conduit/projects/conduit-market-client',
failed: true,
timedOut: false,
isCanceled: false,
killed: false
},
packageManager: 'Yarn Berry',
packageName: 'storybook'
},
fromStorybook: true,
category: 'CLI',
documentation: false,
code: 1
}

npx storybook@latest init using both Node v18.20.5 and v20.10.0 produces the following:

npx storybook@latest init

╭──────────────────────────────────────────────────────╮
│ │
│ Adding Storybook version 8.4.7 to your project.. │
│ │
╰──────────────────────────────────────────────────────╯
• Detecting project type. ✓
Installing dependencies...

npm error code EUNSUPPORTEDPROTOCOL
npm error Unsupported URL Type "link:": link:./src/types
npm error A complete log of this run can be found in: /Users/aceaspades/.npm/_logs/2024-12-08T02_00_42_027Z-debug-0.log
An error occurred while installing dependencies.

And finally, deno run -A npm:storybook@latest init using both Node v18.20.5 and v20.10.0 produces the following:

deno run -A npm:storybook@latest init

❯ deno run -A npm:storybook@latest init
╭──────────────────────────────────────────────────────╮
│ │
│ Adding Storybook version 8.4.7 to your project.. │
│ │
╰──────────────────────────────────────────────────────╯
• Detecting project type. ✓
Installing dependencies...

npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "link:": link:./src/types

npm ERR! A complete log of this run can be found in: /Users/aceaspades/.npm/_logs/2024-12-08T02_01_57_167Z-debug-0.log
An error occurred while installing dependencies.

Noticing the error message stating that I need a package.json, I configured a simple placeholder package.json file, reran yarn dlx storybook@latest init, and this is what I got:

yarn dlx storybook@latest init

➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 1s 139ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ esbuild@npm:0.24.0 must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 0s 738ms
➤ YN0000: Done with warnings in 1s 914ms

SB_CLI_0001 (FindPackageVersionsError): Unable to find versions of "storybook" using Yarn Berry
Reason: Error: Command failed with exit code 1: yarn npm info storybook --fields version --json
error Command "npm" not found.
yarn run v1.22.22
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
at gi.runGetVersions (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/common/index.cjs:19965:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async doInitiate (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/create-storybook/dist/bin/index.cjs:89:1000)
at async withTelemetry (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/core-server/index.cjs:35757:12)
at async initiate (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/create-storybook/dist/bin/index.cjs:127:214) {
data: {
error: Error: Command failed with exit code 1: yarn npm info storybook --fields version --json
error Command "npm" not found.
yarn run v1.22.22
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
at makeError (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/common/index.cjs:18141:67)
at handlePromise (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/common/index.cjs:18759:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async gi.executeCommand (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/common/index.cjs:19205:15)
at async gi.runGetVersions (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/common/index.cjs:19959:15)
at async doInitiate (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/create-storybook/dist/bin/index.cjs:89:1000)
at async withTelemetry (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/@storybook/core/dist/core-server/index.cjs:35757:12)
at async initiate (/Users/aceaspades/.npm/_npx/524cdd656b8fa4a9/node_modules/create-storybook/dist/bin/index.cjs:127:214) {
shortMessage: 'Command failed with exit code 1: yarn npm info storybook --fields version --json',
command: 'yarn npm info storybook --fields version --json',
escapedCommand: 'yarn npm info storybook --fields version --json',
exitCode: 1,
signal: undefined,
signalDescription: undefined,
stdout: 'yarn run v1.22.22\n' +
'info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.',
stderr: 'error Command "npm" not found.',
cwd: '/Users/aceaspades/Projects/conduit/projects/conduit-market-client',
failed: true,
timedOut: false,
isCanceled: false,
killed: false
},
packageManager: 'Yarn Berry',
packageName: 'storybook'
},
fromStorybook: true,
category: 'CLI',
documentation: false,
code: 1
}

Finally, I ran deno run -A npm:storybook@latest init WITH a package.json and got a favorable result:

deno run -A npm:storybook@latest init

❯ deno run -A npm:storybook@latest init
╭──────────────────────────────────────────────────────╮
│ │
│ Adding Storybook version 8.4.7 to your project.. │
│ │
╰──────────────────────────────────────────────────────╯
• Detecting project type. ✓
Installing dependencies...

npm WARN reify invalid or damaged lockfile detected
npm WARN reify please re-try this operation once it completes
npm WARN reify so that the damage can be corrected, or perform
npm WARN reify a fresh install with no lockfile if the problem persists.

removed 8 packages, and audited 1 package in 773ms

found 0 vulnerabilities
We couldn't detect your project type. (code: UNDETECTED)
You can specify a project type explicitly via storybook init --type <type>, see our docs on how to configure Storybook for your framework: https://storybook.js.org/docs/get-started/install

? Do you want to manually choose a Storybook project type to install? ›

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Empathy Backlog
Development

Successfully merging a pull request may close this issue.