Skip to content

Conversation

@icopp
Copy link
Contributor

@icopp icopp commented Dec 12, 2025

Relates to #32898

What I did

This is an attempt to fix the remaining Exported variable '...' has or is using name '...' from external module "/..." but cannot be named errors when using definedPreview().meta().story().

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

  • Using a project with "composite": true
  • Create a simple preview.tsx for a Storybook project, for example:
    import { definePreview } from "@storybook/nextjs";
    
    export default definePreview({
      addons: []
    });
    
  • Create a simple story, for example:
    const meta = preview.meta({
      component: () => null
    });
    export default meta;
    
    export const SomeStory = meta.story();
    
  • See that there are multiple type errors before this change, and fewer type errors after this change

The complex build system and tangled cross-package imports mean I'm not 100% sure that this will fix all type errors, but I don't think it can make anything worse.

Documentation

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

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • New Features
    • Public type definitions now available for Backgrounds, Controls, Highlight, Measure, Outline, Test, Viewport, and Actions features. Provides enhanced TypeScript support for developers integrating the library, improving code quality and developer experience.

✏️ Tip: You can customize this high-level summary in your review settings.

…med` errors

This is an attempt to fix the remaining `Exported variable '...' has or is using name '...' from external module "/..." but cannot be named` errors when using `definedPreview().meta().story()`.
@mrginglymus
Copy link
Contributor

Under CSF4 it's not necessary to export meta, so the easiest fix for this is just to not do that :)

Fwiw I remember encountering this before I realised I didn't need to export meta...but now I can't reproduce it, even with fairly strict type checking

@icopp
Copy link
Contributor Author

icopp commented Dec 12, 2025

Under CSF4 it's not necessary to export meta, so the easiest fix for this is just to not do that :)

The error comes from exporting anything with meta.story(...), which is still needed.

Fwiw I remember encountering this before I realised I didn't need to export meta...but now I can't reproduce it, even with fairly strict type checking

Are you using composite: true? From comments on other issues, that seems to be why only some people are seeing the issue. When using that, any other package using composite: true package needs to be able to import all of the same types, including types used in intersections.

@mrginglymus
Copy link
Contributor

Ahh, I only have composite: true in my build config...but enabling it still doesn't reveal these errors.

@mrginglymus
Copy link
Contributor

This is odd...canot reproduce at all on my repo, but can reproduce on the reproduction repo. It would be ideal if we can get this failing on the sandbox repo too, so that we can catch future regressions.

@icopp
Copy link
Contributor Author

icopp commented Dec 12, 2025

This is odd...canot reproduce at all on my repo, but can reproduce on the reproduction repo. It would be ideal if we can get this failing on the sandbox repo too, so that we can catch future regressions.

If it's any help with that, my company's setup uses a Typescript repo with project references. The root tsconfig.json has (for example)

{
  ...,
  "files": [],
  "references": [
    { "path": "packages/components" },
    { "path": "packages/web" },
    ...
  ]
}

and then the tsconfig.json files in each packages folder have along the lines of:

{
  ...,
  "compilerOptions": {
    "composite": true,
    "module": "ESNext",
    "moduleResolution": "bundler"
  },
  "references": [
    { "path": "../components" }
  ]
}

Type checks are run by just running tsc -b at the root level (which via the references processes the entire monorepo). All references between the packages are via package imports, not direct file references.

@mrginglymus
Copy link
Contributor

I've been using this: https://github.com/cyberuni/sb-composite - which is a pretty minimal reproduction. I just can't work out what's the difference between it and mine...

@mrginglymus
Copy link
Contributor

mrginglymus commented Dec 12, 2025

The meta.story() ones only explode if you call them with no arguments - replacing them with meta.story({}) and they work fine, which suggests there's something wrong with the typing of the function (rather than an issue with non-exported types).

The export issue in main doesn't reproduce under yarn..

@icopp
Copy link
Contributor Author

icopp commented Dec 12, 2025

The meta.story() ones only explode if you call them with no arguments - replacing them with meta.story({}) and they work fine, which suggests there's something wrong with the typing of the function (rather than an issue with non-exported types).

The export issue in main doesn't reproduce under yarn..

In my company's repo I still get the errors for BackgroundsGlobals and ViewportGlobals when doing meta.story({}), as well as an additional error: Property 'args' is missing in type '{}' but required in type ... (with the big inferred type out of meta.

@mrginglymus
Copy link
Contributor

Well that's very doomed :)

Typescript version?

@icopp
Copy link
Contributor Author

icopp commented Dec 14, 2025

Well that's very doomed :)

Typescript version?

5.8.3 (with tsc -b).

An interesting thing here is that from checking again, the errors with meta.story({}) aren't actually showing up for every component. Some stories have no errors, some stories have multiple errors, even with components with similar props.

For a simplified example:

// callout.stories.ts

import { faWandMagicSparkles } from "@fortawesome/pro-regular-svg-icons";

import preview from "#.storybook/preview";

import CalloutComponent from "./callout";

const meta = preview.meta({
  component: CalloutComponent,
  title: "Blocks/Callout",
  argTypes: {
    children: { control: "text" },
    color: {
      type: {
        name: "enum",
        value: ["gray", "red", "green"],
      },
    },
    icon: {
      control: "select",
    },
  },
  args: {
    children: "This is a callout.",
    color: "gray",
    icon: faWandMagicSparkles,
  },
});

export const Callout = meta.story({});

The callout.stories.ts file has no errors.

// platform-label.stories.ts

import preview from "#.storybook/preview";

import PlatformLabelComponent from "./platform-label";

const meta = preview.meta({
  component: PlatformLabelComponent,
  title: "Messages/Platform Label",
  argTypes: {
    children: { control: false },
    platform: {
      control: "select",
      type: {
        name: "enum",
        required: true,
        value: ["facebook", "youtube"],
      },
    },
  },
  args: {
    platform: "facebook",
  },
});

export const PlatformLabel = meta.story({});

The platform-label.stories.ts file has errors for the PlatformLabel declaration (the BackgroundsGlobals and ViewportGlobals ones) and the Property 'args' is missing error on the {}. Weirdly enough, if I just copy in the same args property there, there's no error (but the BackgroundsGlobals and ViewportGlobals errors remain), even though it should obviously be inheriting that from meta declaration.

The only difference I can think of that would somehow play into it is that the PlatformLabel component has some complicated typing on children (children?: ((message: string) => React.ReactNode | null) | undefined), and maybe things in meta.story() are either wrongly assuming that children can only be ReactNode and breaking otherwise, or pulling in different types based on the type of children.

@nx-cloud
Copy link

nx-cloud bot commented Dec 15, 2025

View your CI Pipeline Execution ↗ for commit c2f16e3


☁️ Nx Cloud last updated this comment at 2025-12-15 14:07:50 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 2025

📝 Walkthrough

Walkthrough

Added re-exported type declarations from preview modules to core-annotations.ts, exposing ActionsTypes, BackgroundsGlobals, BackgroundTypes, ControlsTypes, HighlightTypes, MeasureTypes, OutlineTypes, TestTypes, ViewportGlobals, and ViewportTypes from their respective module paths.

Changes

Cohort / File(s) Change Summary
Type re-exports
code/core/src/csf/core-annotations.ts
Added nine re-exported type declarations from preview modules (actions, backgrounds, controls, highlight, measure, outline, test, viewport) to expand public API surface

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

  • Straightforward type re-exports with no logic changes or dependencies to validate
  • Single file modified with consistent, repetitive re-export pattern

Possibly related PRs

  • storybookjs/storybook#33216: Adds missing type-only re-exports (BackgroundsGlobals, ViewportGlobals, and other preview types) to expand the public API surface.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f262ad and c2f16e3.

📒 Files selected for processing (1)
  • code/core/src/csf/core-annotations.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use ESLint and Prettier configurations that are enforced in the codebase

Files:

  • code/core/src/csf/core-annotations.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Enable TypeScript strict mode

Files:

  • code/core/src/csf/core-annotations.ts
code/**/*.{ts,tsx,js,jsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{ts,tsx,js,jsx,mjs}: Use server-side logger from 'storybook/internal/node-logger' for Node.js code
Use client-side logger from 'storybook/internal/client-logger' for browser code
Do not use console.log, console.warn, or console.error directly unless in isolated files where importing loggers would significantly increase bundle size

Files:

  • code/core/src/csf/core-annotations.ts
code/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Export functions that need to be tested from their modules

Files:

  • code/core/src/csf/core-annotations.ts
code/**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{js,jsx,json,html,ts,tsx,mjs}: Run Prettier with --write flag to format code before committing
Run ESLint with yarn lint:js:cmd to check for linting issues and fix errors before committing

Files:

  • code/core/src/csf/core-annotations.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Select/Select.tsx:200-204
Timestamp: 2025-11-05T09:38:47.712Z
Learning: Repo: storybookjs/storybook — Guidance: Until Storybook 11 is released, do not suggest using React.useId anywhere (e.g., in code/core/src/components/components/Select/Select.tsx) to maintain compatibility with React 17 runtimes. Prefer advising: accept a caller-provided props.id and, if needed, generate a client-only fallback id to minimize SSR hydration issues — but avoid useId. Resume prompting for useId after Storybook 11.
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx} : Export functions that need to be tested from their modules
Learnt from: ndelangen
Repo: storybookjs/storybook PR: 32507
File: code/core/src/manager/globals/globals-module-info.ts:25-33
Timestamp: 2025-09-24T09:39:39.233Z
Learning: In Storybook, storybook/actions/decorator is a preview-only entrypoint and should not be included in manager globals configuration. The duplicatedKeys array in code/core/src/manager/globals/globals-module-info.ts is specifically for manager-side externalization, not preview entrypoints.
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx} : Export functions that need to be tested from their modules

Applied to files:

  • code/core/src/csf/core-annotations.ts
📚 Learning: 2025-09-24T09:39:39.233Z
Learnt from: ndelangen
Repo: storybookjs/storybook PR: 32507
File: code/core/src/manager/globals/globals-module-info.ts:25-33
Timestamp: 2025-09-24T09:39:39.233Z
Learning: In Storybook, storybook/actions/decorator is a preview-only entrypoint and should not be included in manager globals configuration. The duplicatedKeys array in code/core/src/manager/globals/globals-module-info.ts is specifically for manager-side externalization, not preview entrypoints.

Applied to files:

  • code/core/src/csf/core-annotations.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: normal
🔇 Additional comments (1)
code/core/src/csf/core-annotations.ts (1)

13-20: Type re-exports look correct and should address “cannot be named” issues

Re-exporting these preview types from the same modules that define them aligns with how CoreTypes is composed and should make the intersection constituents fully nameable in composite/project‑references setups. No runtime behavior is affected, and the imports above stay consistent with these exports.

Please re-run:

#!/bin/bash
# From your monorepo root
tsc -b

# And in the minimal repro repo
yarn tsc -b || npm run build:types

to confirm the remaining “has or is using name ... but cannot be named” diagnostics are gone (or to see which additional types, if any, still need re-exporting.


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.

@storybook-app-bot
Copy link

Package Benchmarks

Commit: c2f16e3, ran on 15 December 2025 at 14:19:09 UTC

The following packages have significant changes to their size or dependencies:

@storybook/nextjs-vite

Before After Difference
Dependency count 127 128 🚨 +1 🚨
Self size 1.12 MB 1.12 MB 🚨 +36 B 🚨
Dependency size 21.97 MB 21.96 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react-native-web-vite

Before After Difference
Dependency count 159 160 🚨 +1 🚨
Self size 30 KB 30 KB 🚨 +36 B 🚨
Dependency size 23.15 MB 23.14 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react-vite

Before After Difference
Dependency count 117 118 🚨 +1 🚨
Self size 35 KB 35 KB 🚨 +17 B 🚨
Dependency size 19.76 MB 19.75 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@unional
Copy link
Contributor

unional commented Dec 15, 2025

@icopp is it possible that you have multiple versions of storybook in your node_modules? Maybe dedupe and/or delete node_modules and reinstall would help.

@icopp
Copy link
Contributor Author

icopp commented Dec 15, 2025

@icopp is it possible that you have multiple versions of storybook in your node_modules? Maybe deduce and/or delete node_modules and reinstall would help.

That was literally the first thing I checked. There's only one version in node_modules, and directly editing the file at node_modules/storybook/dist/csf/index.d.ts to export the BackgroundsGlobals and ViewportGlobals types declared there in the built file fixes the type error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants