Skip to content

fix(storybook): remove custom-babel-loader workaround#36385

Open
PaulGMardling wants to merge 4 commits into
microsoft:masterfrom
PaulGMardling:fix/remove-custom-babel-loader
Open

fix(storybook): remove custom-babel-loader workaround#36385
PaulGMardling wants to merge 4 commits into
microsoft:masterfrom
PaulGMardling:fix/remove-custom-babel-loader

Conversation

@PaulGMardling

Copy link
Copy Markdown
Contributor

Previous Behavior

swc-loader passes sourcemaps to subsequent Webpack loaders as raw JSON strings (the native output format of SWC). When the react-storybook-addon-export-to-sandbox post-loader ran babel-loader on story files, babel-loader forwarded that string directly to Babel core, which only accepts boolean | object | undefined for inputSourceMap — causing the build

Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: .inputSourceMap must be a boolean, object, or undefined

A custom wrapper custom-babel-loader.ts was introduced to intercept the call and parse the string before passing it to babel-loader.

New Behavior

parseMap: true.
This tells swc-loader to parse its output sourcemap to an object before passing it downstream, so all subsequent loaders receive an object instead of a string. babel-loader can then be used directly in the addon's webpack rule — no custom wrapper needed.
custom-babel-loader.ts is deleted.

Related Issue(s)

#32290

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

📊 Bundle size report

✅ No changes found

@github-actions

Copy link
Copy Markdown

Pull request demo site: URL

Comment thread .agents/skills/link-workspace-packages/SKILL.md Outdated
@PaulGMardling
PaulGMardling force-pushed the fix/remove-custom-babel-loader branch 2 times, most recently from adfff63 to 40f3976 Compare July 13, 2026 08:15
@PaulGMardling
PaulGMardling marked this pull request as ready for review July 13, 2026 14:36
@PaulGMardling
PaulGMardling requested a review from a team as a code owner July 13, 2026 14:37
@tudorpopams
tudorpopams requested a review from Hotell July 14, 2026 12:06
Comment thread scripts/storybook/src/rules.js Outdated
// Parse the source map to an object so subsequent loaders (e.g. babel-loader) receive
// an object rather than the raw JSON string that @swc/core outputs.
// Without this, babel-loader throws: "Error: .inputSourceMap must be a boolean, object, or undefined"
parseMap: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if this isn't default swc setting, this is a breaking change then.

  • can you double check

the question is if this is worth the churn in user land.

@dmytrokirpa mentioned in the originating issue some other options ( order re-shuffle ), have we explored that as an alternative ?

@PaulGMardling PaulGMardling Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Hotell
Confirmed that parseMap is not enabled by default in swc-loader.

Rather than changing the shared @fluentui/scripts-storybook configuration, I moved the add-on's Babel transform to enforce: 'pre'. This keeps the fix within the published add-on and avoids requiring external consumers to configure their SWC loader in a particular way. Babel uses parser-only TypeScript and JSX support, while SWC remains responsible for transpiling.

I also added a build-dependent Nx integration test that runs Webpack against the addon's compiled CommonJS output. It covers:

  • Default SWC string source maps
  • Typed TSX stories
  • Preservation of the original source in fullSource
  • Final source map composition

The v9 Storybook Webpack build also completes without the inputSourceMap error.

@PaulGMardling
PaulGMardling force-pushed the fix/remove-custom-babel-loader branch from 40f3976 to 0daa97b Compare July 15, 2026 15:06
@PaulGMardling PaulGMardling self-assigned this Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Storybook]: Get rid of custom-babel-loader

2 participants