Skip to content

Conversation

@ndelangen
Copy link
Member

@ndelangen ndelangen commented Jan 13, 2026

What I did

We had a conversation about a bug, where users are presented with a warning from NodeJS about the fact that main.js is a ESM formatted file, but it's assumed to be CJS in the case where users have packageJson.type as commonjs (default).

We do not know how common this situation is, we do know that about 15% of init do not use TypeScipt.

We internally debated how important it is to address the bug, and agrees, we should investigate the data a bit more, and determine how many users are affected.

For this we need to know the user's packageJson.type field.
If it turns out a significant portion has none or commonjs we deem it important to figure out a fix.

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

I suspect, no manual testing is required; since all the code to load packageJson was already present, we're only adding 1 additional field to an pre-existing system.

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

Release Notes

  • New Features
    • Enhanced telemetry data collection to track your project's module type configuration, capturing whether your package uses ESM (module) or CommonJS format for improved analytics and diagnostics.

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

@ndelangen ndelangen changed the title add packageJson.type to telemetry Jan 13, 2026
@ndelangen ndelangen self-assigned this Jan 13, 2026
@ndelangen ndelangen requested review from shilman and yannbf January 13, 2026 11:18
@nx-cloud
Copy link

nx-cloud bot commented Jan 13, 2026

View your CI Pipeline Execution ↗ for commit 5bfcbe7

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ✅ Succeeded 9m 33s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-13 11:30:27 UTC

@nx-cloud
Copy link

nx-cloud bot commented Jan 13, 2026

View your CI Pipeline Execution ↗ for commit 5bfcbe7


☁️ Nx Cloud last updated this comment at 2026-01-13 11:19:10 UTC

@ndelangen ndelangen marked this pull request as ready for review January 13, 2026 13:23
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 13, 2026

📝 Walkthrough

Walkthrough

This PR extends the Storybook telemetry payload by introducing a new optional field packageJsonType to the StorybookMetadata interface. The field captures the package.json module type with allowed values 'unknown', 'module', or 'commonjs', with a default value of 'unknown' when computed.

Changes

Cohort / File(s) Summary
Telemetry Type Extension
code/core/src/telemetry/types.ts, code/core/src/telemetry/storybook-metadata.ts
Added optional packageJsonType?: 'unknown' | 'module' | 'commonjs' field to StorybookMetadata interface and implemented its computation with a default value of 'unknown'

Estimated Code Review Effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly Related PRs

  • storybookjs/storybook#32859 — Extends telemetry type definitions in the same code/core/src/telemetry/types.ts file with additional metadata fields.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 283d093 and 5bfcbe7.

📒 Files selected for processing (2)
  • code/core/src/telemetry/storybook-metadata.ts
  • code/core/src/telemetry/types.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,jsx,ts,tsx,json,md,html,css,scss}

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

Format code using Prettier with yarn prettier --write <file>

Files:

  • code/core/src/telemetry/types.ts
  • code/core/src/telemetry/storybook-metadata.ts
**/*.{js,jsx,json,html,ts,tsx,mjs}

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

Run ESLint checks using yarn lint:js:cmd <file> or the full command cross-env NODE_ENV=production eslint --cache --cache-location=../.cache/eslint --ext .js,.jsx,.json,.html,.ts,.tsx,.mjs --report-unused-disable-directives to fix linting errors before committing

Files:

  • code/core/src/telemetry/types.ts
  • code/core/src/telemetry/storybook-metadata.ts
**/*.{ts,tsx}

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

Enable TypeScript strict mode across all packages

Files:

  • code/core/src/telemetry/types.ts
  • code/core/src/telemetry/storybook-metadata.ts
**/*.{ts,tsx,js,jsx}

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

**/*.{ts,tsx,js,jsx}: Export functions from modules if they need to be tested
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/telemetry/types.ts
  • code/core/src/telemetry/storybook-metadata.ts
code/{core,lib,addons,builders,frameworks,presets}/**/*.{ts,tsx,js,jsx}

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

Use logger from storybook/internal/node-logger for server-side logging in Node.js code

Files:

  • code/core/src/telemetry/types.ts
  • code/core/src/telemetry/storybook-metadata.ts
🧬 Code graph analysis (1)
code/core/src/telemetry/storybook-metadata.ts (1)
code/core/src/common/js-package-manager/JsPackageManager.ts (1)
  • packageJson (790-792)
🔇 Additional comments (2)
code/core/src/telemetry/types.ts (1)

81-81: LGTM!

The new optional packageJsonType field is well-defined with appropriate union type values that cover the standard Node.js package types plus a sensible 'unknown' fallback.

code/core/src/telemetry/storybook-metadata.ts (1)

225-225: The type assignment is correct and type-safe.

PackageJson.type from type-fest is typed as 'module' | 'commonjs' | undefined, and the nullish coalescing operator ?? correctly narrows undefined to 'unknown', producing the expected 'unknown' | 'module' | 'commonjs' type that matches StorybookMetadata.packageJsonType. No changes needed.


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

@ndelangen ndelangen merged commit ce33702 into next Jan 14, 2026
79 of 83 checks passed
@ndelangen ndelangen deleted the norbert/telemetry-add-packagejson-type branch January 14, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment