Skip to content

[internals] Fix ERR_UNSUPPORTED_DIR_IMPORT for core-js-pure in Node ESM#22985

Merged
michelengelen merged 2 commits into
mui:masterfrom
michelengelen:bugfix/internal/22984
Jun 29, 2026
Merged

[internals] Fix ERR_UNSUPPORTED_DIR_IMPORT for core-js-pure in Node ESM#22985
michelengelen merged 2 commits into
mui:masterfrom
michelengelen:bugfix/internal/22984

Conversation

@michelengelen

Copy link
Copy Markdown
Member

The @mui/x-internals/disposable module imported core-js-pure using bare directory paths (core-js-pure/actual/disposable-stack). Node's native ESM loader does not support directory imports for packages without an exports field, causing ERR_UNSUPPORTED_DIR_IMPORT crashes in SSR environments (Vite, TanStack Start, Next.js) where MUI X packages are left external. Fixes by switching to explicit file paths (…/index.js), the same resolution the issue reporter and Node's own error message suggest.

Fixes #22984

@michelengelen michelengelen self-assigned this Jun 29, 2026
@michelengelen
michelengelen requested a review from romgrk as a code owner June 29, 2026 07:34
@michelengelen michelengelen added type: bug It doesn't behave as expected. scope: all components Widespread work has an impact on almost all components. labels Jun 29, 2026

@brijeshb42 brijeshb42 left a comment

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.

Just FYI, code-js-pure as a dependency of x-internals has ^ version range.

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 29, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-22985--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@michelengelen

Copy link
Copy Markdown
Member Author

@brijeshb42 the linter fails with Unexpected use of file extension ... should we just disable the rule on those lines?

@brijeshb42

Copy link
Copy Markdown
Contributor

I remembered we have cjs/esm outputs. What happens in that case for cjs/esm usage since both will be importing from same path ?

@brijeshb42

Copy link
Copy Markdown
Contributor

We had a lot of back & forth for a similar fix in core - mui/material-ui#48645

@michelengelen

Copy link
Copy Markdown
Member Author

I remembered we have cjs/esm outputs. What happens in that case for cjs/esm usage since both will be importing from same path ?

This case is simpler than the react-transition-group situation in material-ui — core-js-pure ships only CommonJS, no ESM build. actual/disposable-stack/index.js is always a CJS file regardless of which output of @mui/x-internals is consuming it:

  • CJS consumers: require('core-js-pure/actual/disposable-stack/index.js') — plain CJS load, works as before.
  • ESM consumers via bundlers: bundlers (Vite, webpack, Rollup) handle CJS→ESM interop and don't care about the extension.
  • Native Node ESM: import of a .js CJS file is supported — Node wraps module.exports as the default export.

There's no split ESM/CJS build in core-js-pure to worry about, so a single explicit path serves all three cases. That's exactly why this is a simpler fix than the RTG case.

@michelengelen
michelengelen enabled auto-merge (squash) June 29, 2026 08:31
@michelengelen
michelengelen merged commit e636363 into mui:master Jun 29, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: all components Widespread work has an impact on almost all components. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@mui/[email protected] disposable entry breaks Node-native ESM / SSR with ERR_UNSUPPORTED_DIR_IMPORT

2 participants