Skip to content

Conversation

valentinpalkovic
Copy link
Contributor

@valentinpalkovic valentinpalkovic commented May 16, 2025

Closes #22070

What I did

Added support for Next.js' module transpilation feature

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

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

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 pull request has been released as version 0.0.0-pr-31501-sha-8f7da28d. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-31501-sha-8f7da28d
Triggered by @valentinpalkovic
Repository storybookjs/storybook
Branch valentin/fix-nextjs-module-transpilation
Commit 8f7da28d
Datetime Thu May 22 08:31:17 UTC 2025 (1747902677)
Workflow run 15181834915

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=31501

Greptile Summary

Implements Next.js's transpilePackages configuration in Storybook to fix module transpilation issues, enabling proper handling of ES6 packages in node_modules.

  • Added getNodeModulesExcludeRegex utility in code/frameworks/nextjs/src/utils.ts to generate dynamic exclude patterns
  • Updated Babel loader in code/frameworks/nextjs/src/babel/loader.ts to use transpilePackages config
  • Modified SWC loader in code/frameworks/nextjs/src/swc/loader.ts to support package transpilation
  • Enhanced preset configuration in code/frameworks/nextjs/src/preset.ts to properly handle both Babel and SWC compilation

@valentinpalkovic valentinpalkovic self-assigned this May 16, 2025
Copy link

nx-cloud bot commented May 16, 2025

View your CI Pipeline Execution ↗ for commit 599144c.

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 1m 26s View ↗

☁️ Nx Cloud last updated this comment at 2025-05-30 06:30:34 UTC

@michio-dev-my
Copy link

Hi @valentinpalkovic 👋

Thanks for this PR, I didn't know how to fix it myself.
can you please request canary release for this, I will help with testing it out.

This is very useful with libraries like nativewind, react-native-primitives etc.

@valentinpalkovic
Copy link
Contributor Author

Hi @michio-dev-my

Here you go: 0.0.0-pr-31501-sha-8f7da28d (ready in like 20 minutes)

Could you maybe provide a minimal reproduction so that I can also test it out?

@storybook-pr-benchmarking
Copy link

storybook-pr-benchmarking bot commented May 22, 2025

Package Benchmarks

Commit: 599144c, ran on 30 May 2025 at 06:33:52 UTC

No significant changes detected, all good. 👏

@michio-dev-my
Copy link

@valentinpalkovic thank you so much, sure sure will do the reproduction repo as well.

@TheMichio
Copy link

Hi @valentinpalkovic 👋

I'm the same guy but with my own personal github account and not with company account.

thank you so much for this update, it fixed the issue with nextjs transpilePackages issue.

you can find the repo to test it out here: https://github.com/TheMichio/nativewind-nextjs-storybook

I tried to setup the same setup in a monorepo setup, but there was some issue with jsxImportSource which I don't know is related to storybook or monorepo setup. that is a complete issue. I will check it out after releasing this.

but if you want that reproduction repo I will share it with you as well. 🙇

@TheMichio
Copy link

Hi @valentinpalkovic 👋

Can you please check the reproduction repo and if everything is ok merge this to next release?

@valentinpalkovic valentinpalkovic marked this pull request as ready for review May 30, 2025 06:24
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile

import { getNodeModulesExcludeRegex } from '../utils';

export const configureBabelLoader = async (
baseConfig: any,
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using a more specific type than 'any' for baseConfig

@TheMichio
Copy link

Hi @valentinpalkovic 👋

Is there anything else I can do to help with merging this to the next version?

I'm really pending on this feature 🙇

@valentinpalkovic
Copy link
Contributor Author

Hi @TheMichio,

Nothing pending. I've just forgotten about it. :)

@valentinpalkovic valentinpalkovic added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Jun 3, 2025
@valentinpalkovic valentinpalkovic merged commit a0d1b3e into next Jun 3, 2025
55 of 62 checks passed
@valentinpalkovic valentinpalkovic deleted the valentin/fix-nextjs-module-transpilation branch June 3, 2025 10:32
valentinpalkovic added a commit that referenced this pull request Jun 5, 2025
…-transpilation

Next.js: Fix module transpilation

(cherry picked from commit a0d1b3e)
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ci:normal nextjs patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Next.js module transpilation is not supported
3 participants