storybook icon indicating copy to clipboard operation
storybook copied to clipboard

[Bug]: `upgrade` command always throws `UpgradeStorybookToSameVersionError` when using `pnpx`

Open JReinhold opened this issue 5 months ago • 2 comments

Describe the bug

Running pnpm dlx storybook@next upgrade in @storybook/addon-onboarding throws UpgradeStorybookToSameVersionError, although the project uses Storybook dependencies with the version 7.1.0-alpha.38. Everything works fine when using npx storybook@next upgrade.

To Reproduce

  1. npx storybook@latest sandbox
  2. cd into sandbox
  3. pnpm install
  4. pnpx storybook@next upgrade
  5. Get error

System

No response

Additional context

Originally posted by @valentinpalkovic in https://github.com/storybookjs/storybook/discussions/25692#discussioncomment-8230065

This happens because we use require.resolve('@storybook/cli/package.json') to get the actual package path, and then check the version field in the package.json. However require.resolve in pnpx will get its own package and not the one in the actual working directory.

We need to change the logic to the package manager's CLI what version is installed in CWD (eg. pnpm why @storybook/cli), and then parse that output to determine the current version.

yarn dlx with Yarn 1 works, but 2+ has a similar issue where it can't detect the existing version so it just assumes v0.0.0

JReinhold avatar Jan 24 '24 10:01 JReinhold

Hah, I just noticed this as well when using pnpm dlx sb@latest upgrade in my project and came to see if there was already an issue about it. Thanks for filing it!

I also saw that npx is a bit wonky too, because it tells me:

 Upgrading Storybook from version 0.0.0 to version 7.6.10.

When my current version is really 7.6.0-alpha.6

IanVS avatar Jan 24 '24 13:01 IanVS

@IanVS could you try with npx [email protected] upgrade from #25752 ? I've tested it with all the different executors and it works for me, but I haven't run into the issue using npx like you have, so you might have another setup that I'd like to see work too.

JReinhold avatar Jan 26 '24 10:01 JReinhold

This is what I see with that canary:

╭─────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                     │
│   Upgrading Storybook from version 7.6.0 to version 0.0.0-pr-25752-sha-424630b7..   │
│   This is a pre-release version.                                                    │
│                                                                                     │
╰─────────────────────────────────────────────────────────────────────────────────────╯

IanVS avatar Jan 29 '24 15:01 IanVS

same for me

gluecksmensch avatar Jan 29 '24 15:01 gluecksmensch