Skip to content

fix(version): support ESM and new v8+ conventional-changelog preset API#4302

Merged
JamesHenry merged 2 commits intolerna:mainfrom
AI-JamesHenry-Org:4021
Mar 11, 2026
Merged

fix(version): support ESM and new v8+ conventional-changelog preset API#4302
JamesHenry merged 2 commits intolerna:mainfrom
AI-JamesHenry-Org:4021

Conversation

@AI-JamesHenry
Copy link
Copy Markdown
Collaborator

@AI-JamesHenry AI-JamesHenry commented Mar 11, 2026

Note

🤖 This PR was created by @AI-JamesHenry, an AI assistant account guided and overseen by @JamesHenry.

Summary

  • Adds dynamic import() fallback when require() fails with ERR_REQUIRE_ESM (Node 20), enabling support for ESM-only conventional-changelog presets (v8+)
  • Unwraps __esModule module namespace objects returned by require() of ESM modules on Node 22+ (where require() succeeds but returns a namespace wrapper instead of the default export)
  • Normalizes the new v8+ preset config API shape (parser/writer/commits/whatBump) to the legacy format (parserOpts/writerOpts/gitRawCommitsOpts/conventionalChangelog/recommendedBumpOpts) expected by conventional-changelog-core@5 and conventional-recommended-bump@7
  • Adds unit tests covering the new preset API format for both version recommendation and changelog generation

Reproduction

conventional-changelog-conventionalcommits v8+ (and other preset packages) switched to:

  1. ESM-only ("type": "module") — on Node 20, require() throws ERR_REQUIRE_ESM; on Node 22+, require() succeeds but returns a module namespace object { __esModule, default, ... } instead of the default export
  2. New config shape{ parser, writer, commits, whatBump } instead of { parserOpts, writerOpts, gitRawCommitsOpts, recommendedBumpOpts, conventionalChangelog }

This caused Lerna to either fail to load the preset entirely (ESM error) or produce degraded changelogs (missing version links, missing "Bug Fixes" section headings, missing "closes" references).

Verified with pkg.pr.new release (aac0ed8)

Preset Version Link Bug Fixes Heading Custom Issue URL Result
conventionalcommits@7.0.2 (CJS, old API) [1.0.1](...) ### Bug Fixes [TEST-123](https://myBugTracker.com/TEST-123) PASS
conventionalcommits@9.3.0 (ESM, new API) [1.0.1](...) ### Bug Fixes [TEST-123](https://myBugTracker.com/TEST-123) PASS

Node version coverage

Node require() of ESM Handling
20.x Throws ERR_REQUIRE_ESM import() fallback extracts .default
22.12+ Returns namespace { __esModule, default } __esModule check extracts .default
24+ Same as 22.12+ Same __esModule check

Test plan

  • New unit test: supports new v8+ preset API with parser/writer/whatBump (recommendVersion)
  • New unit test: normalizes new v8+ preset API to legacy format (getChangelogConfig)
  • New unit test: supports new v8+ preset API for changelog generation (updateChangelog)
  • All 500 existing unit tests pass
  • Build, lint, format checks pass
  • Manual verification with pkg.pr.new release against both v7 and v9 presets

Closes #4021
Closes #4089
Closes #4184

conventional-changelog preset packages v8+ are ESM-only and use a new
config API shape (parser/writer/commits/whatBump instead of
parserOpts/writerOpts/gitRawCommitsOpts/recommendedBumpOpts). This
adds dynamic import() fallback for ESM modules and normalizes the new
API shape to the legacy format expected by conventional-changelog-core
and conventional-recommended-bump.

Closes lerna#4021
@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 11, 2026

View your CI Pipeline Execution ↗ for commit aac0ed8

Command Status Duration Result
nx run-many --t e2e --parallel=1 ✅ Succeeded 11m 27s View ↗
nx run-many -t test --parallel=3 --ci --maxWork... ✅ Succeeded 1m 7s View ↗
nx run-many -t build --parallel=3 ✅ Succeeded 40s View ↗
nx run-many -t lint --parallel=3 ✅ Succeeded 40s View ↗
nx run integration:integration --ci --maxWorkers=2 ✅ Succeeded 9s View ↗
nx-cloud record -- npx nx format:check ✅ Succeeded 2s View ↗
nx run-many -t build ✅ Succeeded <1s View ↗
nx run-many -t test --parallel=3 --ci --maxWork... ✅ Succeeded 3m 38s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-11 13:50:21 UTC

JamesHenry

This comment was marked as outdated.

@AI-JamesHenry AI-JamesHenry marked this pull request as draft March 11, 2026 13:36
Node.js 22+ can require() ESM modules without throwing ERR_REQUIRE_ESM,
but returns a module namespace object { __esModule, default, ... }
instead of the default export directly. Extract .default when this
interop wrapper is detected.
JamesHenry

This comment was marked as outdated.

@JamesHenry JamesHenry marked this pull request as ready for review March 11, 2026 14:30
@JamesHenry JamesHenry merged commit 575b248 into lerna:main Mar 11, 2026
17 checks passed
literat added a commit to alma-oss/spirit-design-system that referenced this pull request Mar 31, 2026
…lerna.json

  * current lerna version finally support esm for conventional commits
  * @see: lerna/lerna#4302
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot find module 'conventionalcommits' support conventional-changelog-conventionalcommits v8 changelogPreset no longer working as expected

2 participants