Skip to content

SB10: ESM-only #31819

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

Draft
wants to merge 222 commits into
base: next
Choose a base branch
from
Draft

SB10: ESM-only #31819

wants to merge 222 commits into from

Conversation

ndelangen
Copy link
Member

@ndelangen ndelangen commented Jun 19, 2025

What I did

This is the target branch of all ESM-only related work for Storybook v10

🦋 Canary release

This pull request has been released as version 0.0.0-pr-31819-sha-8b752a73. Try it out in a new sandbox by running npx storybook@0.0.0-pr-31819-sha-8b752a73 sandbox or in an existing project with npx storybook@0.0.0-pr-31819-sha-8b752a73 upgrade.

More information
Published version 0.0.0-pr-31819-sha-8b752a73
Triggered by @ndelangen
Repository storybookjs/storybook
Branch sb10/esm-only
Commit 8b752a73
Datetime Fri Jun 27 18:37:09 UTC 2025 (1751049429)
Workflow run 15933476383

To request a new release of this pull request, mention the @storybookjs/core team.

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

Greptile Summary

Target branch for transitioning Storybook v10 to ESM-only modules, marking a significant architectural shift in package format and module system.

  • Initiates ESM-only architecture for Storybook v10, removing CommonJS support
  • Contains preparation work for ESM transition across all Storybook packages
  • Targets next branch as base for v10 development
  • No canary release yet available, can be requested via @storybookjs/core team mention

ndelangen and others added 30 commits June 17, 2025 16:09
…upport

- Changed Storybook UI commands in package.json to reference core/bin instead of node_modules/storybook.
- Updated package.json in core to use 'default' for common module exports.
- Introduced hooks.mjs and loader.mjs for improved ESM handling and TypeScript support.
- Modified interopRequireDefault function to handle dynamic imports and fallback to CommonJS.
…async operations

- Changed `loadCustomPresets` and `loadCustomWebpackConfig` functions to be asynchronous, allowing for better handling of dynamic imports.
- Updated the usage of these functions in the relevant files to await their results, ensuring proper configuration loading.
- Removed deprecated `esbuild-register` dependency from package.json.
- Bump Node.js version requirement to 22.16.0 in package.json.
- Update .nvmrc to reflect the new Node.js version.
- Add esbuild dependency version range to package.json and yarn.lock.
- Modify getStorybookInfo calls to be asynchronous in relevant files for better handling of dynamic imports.
- Introduce new hooks.mjs and loader.mjs for enhanced ESM support and TypeScript handling.
- Introduced hooks.mjs and loader.mjs for enhanced ESM handling and TypeScript transformation.
- Updated index.cjs to utilize the new hooks for loading TypeScript files.
- Included bin/**/* in package.json to ensure proper file inclusion.
- Added `./bin/loader.mjs` export to package.json for improved module resolution.
- Removed deprecated `hooks.mjs` files from bin directories.
- Updated `index.cjs` to directly require the dist files, simplifying the loading process.
- Adjusted `generatePackageJsonFile` to handle new export formats for core-server presets.
- Replaced `require.resolve` with `import.meta.resolve` in multiple files for better ESM compatibility.
- Enhanced the `preset` object in `presets.test.ts` to include detailed properties for better testing coverage.
- Marked the `should resolve all addons & presets in correct order` test as skipped in `presets.test.ts` to prevent execution during current test runs.
- Updated `build-index.test.ts` to skip the `should build index` test, indicating a temporary change in test execution status.
…istency

- Added `defaultFavicon` constant to `constants.ts` for better favicon management.
- Updated `common-preset.ts` to import `defaultFavicon`.
- Modified tests in `favicon.test.ts`, `stories-json.test.ts`, and `StoryIndexGenerator.test.ts` to mock `defaultFavicon` and `defaultStaticDirs` for consistent test behavior.
- Updated `standalone.ts` and `common-preset.ts` to replace `import.meta.resolve` with `fileURLToPath` for better ESM support.
- Ensured correct directory resolution for package.json files in both modules.
- Updated `build-static.ts` to use `fileURLToPath` for resolving the directory of `package.json`, improving ESM support.
- This change aligns with recent updates to other files for consistent handling of module paths.
…patibility

- Changed the export in `package.json` from `require` to `default` for telemetry.
- Enhanced the `generatePackageJsonFile` function to include additional checks for ESM-only compatibility, specifically for telemetry files.
…ibility

- Changed the loader resolution in `sandbox-parts.ts` from `import.meta.resolve` to a direct string reference for `@storybook/addon-docs/mdx-loader`, improving consistency with recent ESM updates.
- Eliminated the esbuild version range from `package.json` files in `cli-storybook` and `create-storybook`, as well as from `yarn.lock`, to streamline dependency management and avoid potential conflicts.
- Updated the CircleCI configuration file to use consistent double quotes for strings, enhancing readability and maintaining uniformity across the configuration.
…le extensions

- Updated the loader function in `loader.mjs` to recognize and process multiple TypeScript file extensions, including `.mts`, `.cts`, `.mtsx`, and `.ctsx`, improving compatibility with various TypeScript module formats.
- Changed the version of `@storybook/test-runner` in `sandbox-parts.ts` from `0.22.1--canary.d4862d0.0` to `0.23.1--canary.fd3c654.0` to incorporate the latest features and fixes.
- Corrected the package name from `storybook/test-runner` to `@storybook/test-runner` in `sandbox-parts.ts` to ensure proper dependency resolution.
- Changed the version of `@storybook/test-runner` from `0.23.1--canary.fd3c654.0` to `0.23.1--canary.b6bd5f6.0` in `sandbox-parts.ts` to incorporate the latest updates.
- Added a new step in the CircleCI configuration to install Node.js version 22.15.0 using NVM, ensuring the correct Node version is used during the build process.
- Modified the Node.js installation step in the CircleCI config to use wget instead of curl, and added commands to set up NVM environment variables for better compatibility and reliability during builds.
- Changed the Node.js installation step in the CircleCI config to use version 22.16.0, ensuring the build process utilizes the latest features and improvements.
- Set `minifyWhitespace` to `false` in `bundle.ts` to prevent whitespace minification during the build process.
- Updated the version of `@storybook/test-runner` in `sandbox-parts.ts` from `0.23.1--canary.b6bd5f6.0` to `0.23.1--canary.2094e4b.0` to incorporate the latest updates.
- Updated the version of `@storybook/test-runner` in `sandbox-parts.ts` from `0.23.1--canary.2094e4b.0` to `0.23.1--canary.49024ff.0` to incorporate the latest updates.
- Updated the version of `@storybook/test-runner` in `sandbox-parts.ts` from `0.23.1--canary.49024ff.0` to `0.23.1--canary.de6531a.0` to incorporate the latest updates.
Core: Remove `typesVersions` field from core
Core: Only support ESM version of getAbsolutePath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci: do not merge ci:merged Run the CI jobs that normally run when merged. core esm maintenance User-facing maintenance tasks modern other presets typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants