[bug] Refactor Storybook main config for ESM compatibility. - #8040
Merged
Conversation
Updated imports and path resolution to align with ES module standards, replacing CommonJS-specific methods. This ensures compatibility with modern JavaScript tooling while maintaining functionality.
Replaced relative module imports with explicit 'node:' prefix for core modules. This enhances readability and consistency with current module resolution practices.
Member
|
Thanks! |
Member
|
Breaks storybook for me with Node.js 24. I will revert this PR. {
column: 32,
file: '/Users/vitalyrtishchev/github/mantine/.storybook/main.ts',
length: 11,
line: 9,
lineText: "const currentModuleUrl = typeof import.meta !== 'undefined' ? import.meta.url : '';",
Revert "[core] Fix Storybook compatibility with Node.js 24 (#8040)"
namespace: '',
suggestion: ''
}
"import.meta" is not available with the "cjs" output format and will be empty
SB_CORE-SERVER_0007 (MainFileEvaluationError): Storybook couldn't evaluate your .storybook/main.ts file.
Original error:
ReferenceError: require is not defined in ES module scope, you can use import instead
at file:///.storybook/main.ts:1:46
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:498:37)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:437:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1523:24)
at Module._compile (node:internal/modules/cjs/loader:1674:5)
at Module._compile (/node_modules/esbuild-register/dist/node.js:2258:26)
at node:internal/modules/cjs/loader:1824:10
at Object.newLoader [as .ts] (/node_modules/esbuild-register/dist/node.js:2262:9)
at Module.load (node:internal/modules/cjs/loader:1427:32)
at Module._load (node:internal/modules/cjs/loader:1250:12)
at loadMainConfig (./node_modules/@storybook/core/dist/common/index.cjs:17511:11)
at async buildDevStandalone (./node_modules/@storybook/core/dist/core-server/index.cjs:37134:11)
at async withTelemetry (./node_modules/@storybook/core/dist/core-server/index.cjs:35757:12)
at async dev (./node_modules/@storybook/core/dist/cli/bin/index.cjs:2591:3)
at async s.<anonymous> (./node_modules/@storybook/core/dist/cli/bin/index.cjs:2643:74)
WARN Broken build, fix the error above.
WARN You may need to refresh the browser.
{
column: 32,
file: '/Users/vitalyrtishchev/github/mantine/.storybook/main.ts',
length: 11,
line: 9,
lineText: "const currentModuleUrl = typeof import.meta !== 'undefined' ? import.meta.url : '';",
namespace: '',
suggestion: ''
}
"import.meta" is not available with the "cjs" output format and will be empty
{
column: 32,
file: '/Users/vitalyrtishchev/github/mantine/.storybook/main.ts',
length: 11,
line: 9,
lineText: "const currentModuleUrl = typeof import.meta !== 'undefined' ? import.meta.url : '';",
namespace: '',
suggestion: ''
}
"import.meta" is not available with the "cjs" output format and will be empty |
Contributor
Author
|
Does reverting this PR fix the issue for you? Works fine on my Node.js 24 setup but seems environment-specific. |
Member
|
Yes, reverting the PR fixed issue for me on macOS. |
Contributor
Author
It works fine in 24.2.0, but I think there's an error in 24.3.0! |
Member
|
I use 24.3.0 |
Contributor
Author
Thanks for fixing my code and project too |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
start Storybook Error
This PR refactors the Storybook configuration to ensure compatibility with ECMAScript Modules (ESM). The changes include:
Changes Made
Technical Details
Background
Testing
Related Issue
Fixes storybookjs/storybook#30115
This ensures Storybook configuration works correctly in modern JavaScript environments while maintaining compatibility with existing tooling.