Skip to content

CLI: Add automigrate check for 'storybook' package name conflict#34290

Merged
valentinpalkovic merged 6 commits intostorybookjs:nextfrom
whdjh:fix/28725-storybook-package-name-check
Mar 27, 2026
Merged

CLI: Add automigrate check for 'storybook' package name conflict#34290
valentinpalkovic merged 6 commits intostorybookjs:nextfrom
whdjh:fix/28725-storybook-package-name-check

Conversation

@whdjh
Copy link
Copy Markdown
Contributor

@whdjh whdjh commented Mar 24, 2026

When a project's package.json name is 'storybook', it shadows the real
storybook package in node_modules within npm/pnpm/yarn workspaces,
causing 'Cannot find module storybook/internal/...' errors.

This adds a notification-type automigrate fix that warns users and
suggests renaming their package.

Related to #28725

Closes #28725

What I did

Added a new notification-type automigrate fix (storybookPackageNameConflict) that detects when a project's package.json "name" field is set to "storybook".

In npm/pnpm/yarn workspaces, this creates a symlink at node_modules/storybook that shadows the real Storybook package, causing Cannot find module 'storybook/internal/...' errors. This was identified by @daaashley in #28725 and @shilman suggested adding a CLI check.

The fix warns the user and suggests renaming their package, but does not make automatic changes.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

No manual testing is strictly necessary — the check reads the name field from package.json via packageManager.primaryPackageJson and returns a notification prompt. The logic is fully covered by unit tests (4 test cases: name is "storybook", name is something else, name is undefined, and prompt content verification).

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

N/A — this is a CLI diagnostic check, no user-facing docs needed.

Summary by CodeRabbit

  • New Features

    • Detects when a project's package.json name is "storybook" and warns to avoid module resolution conflicts.
    • Adds an automated migration fix to guide renaming the package name.
  • Tests

    • Adds tests covering detection and user-facing prompt messaging for the package-name conflict.
  • Documentation

    • Standardized quote formatting in ESLint plugin and integration docs.

When a project's package.json name is 'storybook', it shadows the real
storybook package in node_modules within npm/pnpm/yarn workspaces,
causing 'Cannot find module storybook/internal/...' errors.

This adds a notification-type automigrate fix that warns users and
suggests renaming their package.

Related to storybookjs#28725

Made-with: Cursor
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4a385efd-3941-43a1-8d1d-66f1db0d8aa7

📥 Commits

Reviewing files that changed from the base of the PR and between 613cf9c and 93ea5e0.

📒 Files selected for processing (1)
  • code/lib/create-storybook/src/commands/PreflightCheckCommand.test.ts

📝 Walkthrough

Walkthrough

Adds detection and notifications for projects whose package.json "name" is exactly "storybook": a new automigration fix is introduced and registered, and the Create Storybook preflight now warns during setup when this conflict is detected.

Changes

Cohort / File(s) Summary
Automigration fix
code/lib/cli-storybook/src/automigrate/fixes/storybook-package-name-conflict.ts, code/lib/cli-storybook/src/automigrate/fixes/storybook-package-name-conflict.test.ts, code/lib/cli-storybook/src/automigrate/fixes/index.ts
Adds storybookPackageNameConflict Fix that checks packageJson.name === "storybook", provides a notification prompt, test coverage for check/prompt, and registers the fix in allFixes.
Preflight check integration
code/lib/create-storybook/src/commands/PreflightCheckCommand.ts, code/lib/create-storybook/src/commands/PreflightCheckCommand.test.ts
Introduces checkPackageNameConflict invoked during preflight that reads packageManager.primaryPackageJson.packageJson.name and logs a logger.warn when the name equals "storybook"; tests verify warning behavior.
Documentation formatting
code/lib/eslint-plugin/docs/rules/no-stories-of.md, docs/configure/integration/eslint-plugin.mdx
Cosmetic changes: convert examples and frontmatter to use double-quoted string literals and module specifiers (formatting only).

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Preflight as PreflightCheckCommand
  participant PM as JsPackageManager
  participant Logger
  participant Automigrate as storybookPackageNameConflict

  User->>Preflight: run create-storybook
  Preflight->>PM: initialize package manager
  PM-->>Preflight: primaryPackageJson (contains name)
  Preflight->>Preflight: checkPackageNameConflict(name)
  alt name == "storybook"
    Preflight->>Logger: warn about package name conflict
    Logger-->>User: display warning
  end

  User->>Automigrate: run automigrate check
  Automigrate->>PM: read primaryPackageJson.name
  alt name == "storybook"
    Automigrate-->>User: return fix { packageName: "storybook" }
    User->>Automigrate: prompt shown (notification)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
docs/configure/integration/eslint-plugin.mdx (1)

43-46: Optional consistency pass in .eslintrc snippet.

Most snippets now use double quotes, but the .eslintrc example still has single-quoted strings. Consider normalizing that block too for consistency.

Also applies to: 95-100, 108-115, 123-135

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/configure/integration/eslint-plugin.mdx` around lines 43 - 46, The
snippet uses single quotes in the `.eslintrc` example while other snippets use
double quotes; update the string literals to double quotes for consistency
(e.g., in the defineConfig/globalIgnores example and the `.eslintrc` blocks
referenced around lines 95-100, 108-115, 123-135) so all examples use
double-quoted strings consistently; check and replace any remaining
single-quoted keys/values in those code blocks (including occurrences inside
defineConfig, globalIgnores, and the .eslintrc example) to double quotes.
code/lib/eslint-plugin/docs/rules/no-stories-of.md (1)

16-20: Optional: align quote style in the “correct” snippets too.

You updated the incorrect example to double quotes; consider doing the same in the correct examples for full-file consistency.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/lib/eslint-plugin/docs/rules/no-stories-of.md` around lines 16 - 20, The
"correct" example snippets should use double quotes to match the updated
incorrect example; update string literals in the examples (the import path
string and the storiesOf arguments) to use double quotes consistently —
specifically adjust occurrences tied to the import of Button, the storiesOf
call, and the "primary" story label so all quote usage is double quotes for
full-file consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@code/lib/eslint-plugin/docs/rules/no-stories-of.md`:
- Around line 16-20: The "correct" example snippets should use double quotes to
match the updated incorrect example; update string literals in the examples (the
import path string and the storiesOf arguments) to use double quotes
consistently — specifically adjust occurrences tied to the import of Button, the
storiesOf call, and the "primary" story label so all quote usage is double
quotes for full-file consistency.

In `@docs/configure/integration/eslint-plugin.mdx`:
- Around line 43-46: The snippet uses single quotes in the `.eslintrc` example
while other snippets use double quotes; update the string literals to double
quotes for consistency (e.g., in the defineConfig/globalIgnores example and the
`.eslintrc` blocks referenced around lines 95-100, 108-115, 123-135) so all
examples use double-quoted strings consistently; check and replace any remaining
single-quoted keys/values in those code blocks (including occurrences inside
defineConfig, globalIgnores, and the .eslintrc example) to double quotes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dbbea48a-816c-4f60-a127-6b3c65ff4a1e

📥 Commits

Reviewing files that changed from the base of the PR and between a5658d3 and c5f438e.

📒 Files selected for processing (18)
  • code/lib/cli-storybook/src/automigrate/fixes/index.ts
  • code/lib/cli-storybook/src/automigrate/fixes/storybook-package-name-conflict.test.ts
  • code/lib/cli-storybook/src/automigrate/fixes/storybook-package-name-conflict.ts
  • code/lib/eslint-plugin/docs/rules/await-interactions.md
  • code/lib/eslint-plugin/docs/rules/csf-component.md
  • code/lib/eslint-plugin/docs/rules/default-exports.md
  • code/lib/eslint-plugin/docs/rules/hierarchy-separator.md
  • code/lib/eslint-plugin/docs/rules/meta-inline-properties.md
  • code/lib/eslint-plugin/docs/rules/meta-satisfies-type.md
  • code/lib/eslint-plugin/docs/rules/no-redundant-story-name.md
  • code/lib/eslint-plugin/docs/rules/no-renderer-packages.md
  • code/lib/eslint-plugin/docs/rules/no-stories-of.md
  • code/lib/eslint-plugin/docs/rules/no-title-property-in-meta.md
  • code/lib/eslint-plugin/docs/rules/no-uninstalled-addons.md
  • code/lib/eslint-plugin/docs/rules/story-exports.md
  • code/lib/eslint-plugin/docs/rules/use-storybook-expect.md
  • code/lib/eslint-plugin/docs/rules/use-storybook-testing-library.md
  • docs/configure/integration/eslint-plugin.mdx

Update .eslintrc and no-stories-of rule documentation to use
double quotes consistently across all code snippets.

Made-with: Cursor
@whdjh whdjh force-pushed the fix/28725-storybook-package-name-check branch from c5f438e to aac7aff Compare March 24, 2026 05:44
@valentinpalkovic valentinpalkovic moved this to Empathy Queue (prioritized) in Core Team Projects Mar 24, 2026
@valentinpalkovic valentinpalkovic moved this from Empathy Queue (prioritized) to On Hold in Core Team Projects Mar 25, 2026
@valentinpalkovic valentinpalkovic self-assigned this Mar 25, 2026
@valentinpalkovic
Copy link
Copy Markdown
Contributor

valentinpalkovic commented Mar 25, 2026

Hi @whdjh,

Thank you for your contribution!

It is valuable to have an automated migration in place that notifies users of the problem when they attempt to upgrade via the upgrade CLI. What are your thoughts on covering new users who initialize Storybook in a fresh project and therefore don't run the automigration?

@whdjh
Copy link
Copy Markdown
Contributor Author

whdjh commented Mar 25, 2026

"That's a great point. I focused on the upgrade path for this PR since it addresses #28725. Should I open a separate issue/PR for the init case, or would you prefer I extend this one?"

@valentinpalkovic
Copy link
Copy Markdown
Contributor

I would prefer to extend this one instead!

@whdjh
Copy link
Copy Markdown
Contributor Author

whdjh commented Mar 25, 2026

Sounds good! I'll extend the check to the init command as well. Will ping you once it's ready for review.

@whdjh
Copy link
Copy Markdown
Contributor Author

whdjh commented Mar 25, 2026

Hi, @valentinpalkovic
Thanks for the suggestion! I've added the same check to the storybook init flow as well.
The warning is now shown in PreflightCheckCommand (the preflight step of create-storybook) when the project's package.json has "name": "storybook". It warns the user without blocking the init process, consistent with the existing preflight checks (PnP deprecation, version warnings, etc.).

Changes:

  • code/lib/create-storybook/src/commands/PreflightCheckCommand.ts — added checkPackageNameConflict()
  • code/lib/create-storybook/src/commands/PreflightCheckCommand.test.ts — added tests for the new check

This covers both paths now:

  • Existing users upgrading via storybook upgrade → automigrate fix
  • New users running storybook init → preflight warning

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@code/lib/create-storybook/src/commands/PreflightCheckCommand.test.ts`:
- Around line 116-129: The test uses direct access to logger.warn in assertions
which is not type-safe; update the two assertions to use vi.mocked(logger.warn)
so they follow the project's Vitest mocking convention and allow proper mock
typing — locate the expectations in PreflightCheckCommand.test.ts that reference
logger.warn (around the tests for package.json name) and replace those
expect(logger.warn)... and expect(logger.warn).not... calls with
expect(vi.mocked(logger.warn))... while keeping the same expect.stringContaining
checks; no other behavior changes are needed (other related mocks like
scaffoldModule.currentDirectoryIsEmpty and mockPackageManager.primaryPackageJson
remain as-is).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5b3a339f-a4c3-45f5-bc8b-a0d49de15c33

📥 Commits

Reviewing files that changed from the base of the PR and between aac7aff and 613cf9c.

📒 Files selected for processing (2)
  • code/lib/create-storybook/src/commands/PreflightCheckCommand.test.ts
  • code/lib/create-storybook/src/commands/PreflightCheckCommand.ts

@valentinpalkovic valentinpalkovic moved this from On Hold to In Progress in Core Team Projects Mar 26, 2026
@daaashley
Copy link
Copy Markdown

It's about time someone fixed this, good work @whdjh !! 🥳🥳

@whdjh
Copy link
Copy Markdown
Contributor Author

whdjh commented Mar 27, 2026

Thanks! 😀

@valentinpalkovic
Copy link
Copy Markdown
Contributor

I've verified the upgrade and init flow. LGTM!

@valentinpalkovic valentinpalkovic merged commit 88a1f4a into storybookjs:next Mar 27, 2026
114 of 117 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: SB_CORE-SERVER_0002 torybook failed to load the following preset: ./.storybook/main.ts.

4 participants