-
Notifications
You must be signed in to change notification settings - Fork 946
fix: add Node.js v24 ESM compatibility #9949
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
Merged
Merged
Conversation
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
- Add MainFileIsDir export to scopes/component/tracker/esm.mjs
- Create esm.mjs files for @teambit/legacy.bit-map, @teambit/legacy.scope, and @teambit/component-issues
- Convert 122+ require('chai-fs') statements to ESM imports in e2e tests
- Convert chai plugin require statements (chai-arrays, chai-string) to ESM imports
- Fix Node.js v24 stricter ESM/CommonJS interop by providing explicit named exports
Resolves compatibility issues where Node.js v24 requires explicit ESM wrappers
for CommonJS modules to expose named exports properly.
- Add missing exports to tracker module esm.mjs (AddingIndividualFiles, ParentDirTracked, PathOutsideConsumer, VersionShouldBeRemoved)
- Fix lodash named imports in e2e tests to use namespace imports compatible with Node.js v24
- Convert 'import { uniq } from lodash' to 'import * as _ from lodash'
- Convert 'import { difference } from lodash' to 'import * as _ from lodash'
All e2e tests now pass successfully with Node.js v24.4.1
GiladShoham
approved these changes
Sep 2, 2025
- Create scopes/component/component-url/esm.mjs to export ComponentUrl, ScopeUrl, ComponentUrlProvider, useComponentUrl - Fixes webpack resolution error 'Can't resolve @teambit/component.modules.component-url' - Required for proper ESM module resolution during bit build
davidfirst
added a commit
that referenced
this pull request
Oct 3, 2025
This PR fixes lodash import issues in e2e tests that were causing failures with Node.js v24 due to ESM compatibility issues with CommonJS modules. ## Context See #9949
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.
Summary
Adds Node.js v24 ESM compatibility to fix e2e test execution issues. Node.js v24 has stricter ESM/CommonJS interop than v22, requiring explicit configuration for proper module resolution.
Root Cause Analysis
When upgrading from Node.js v22 to v24, e2e tests fail with errors like:
This occurs because:
Node.js v24's stricter ESM/CommonJS boundary: Node.js v24 enforces stricter rules for importing named exports from CommonJS modules, especially when using lazy-loaded exports via Babel's getter functions.
Babel lazy-loading incompatibility: Bit uses Babel's
lazy: () => trueconfiguration which creates getter functions for exports. These getters don't work properly with Node.js v24's ESM interop when importing from CommonJS modules.Pre-compiled components: The problematic modules (
@teambit/legacy.bit-map,@teambit/legacy.scope, etc.) are pre-compiled Bit components stored innode_modules, not source files compiled on-the-fly by Mocha.Why Forcing CommonJS Mode Doesn't Work
We explored forcing CommonJS mode for tests but discovered fundamental limitations:
.tsextensions and are transformed by babel-register to ESM formatSolution: ESM Wrapper Files
Created
.mjswrapper files that provide proper ESM exports for problematic CommonJS modules:components/legacy/bit-map/esm.mjs- Exports BitMap, MissingMainFile, etc.components/legacy/scope/esm.mjs- Exports ScopeNotFound and 50+ other exportscomponents/legacy/consumer/esm.mjs- Exports ConsumerNotFoundscopes/component/tracker/esm.mjs- Exports tracking-related classesscopes/component/component-issues/esm.mjs- Exports IssuesClassesscopes/component/component-url/esm.mjs- Exports URL utilitiesAdditional Changes
exportsconfiguration for dual package supportVerification
All e2e tests now pass successfully with Node.js v24.4.1:
npm run e2e-test # ✅ All tests passThe solution maintains tree-shaking capabilities in production while ensuring compatibility with Node.js v24's stricter module system.