Skip to content

fix(commits): Write the generated commitlint config as a cjs file - #10

Merged
nfebe merged 1 commit into
mainfrom
fix/commitlint-config-esm-repos
Jul 14, 2026
Merged

fix(commits): Write the generated commitlint config as a cjs file#10
nfebe merged 1 commit into
mainfrom
fix/commitlint-config-esm-repos

Conversation

@nfebe

@nfebe nfebe commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

The commit-validation action writes commitlint.config.js with module.exports.
In a consumer whose package.json sets "type": "module" (any Nuxt or ESM
project), Node loads that file as an ES module and the run crashes with
"module is not defined in ES module scope", failing validation before it
checks a single commit message.

Writing the config as commitlint.config.cjs keeps it CommonJS regardless of
the consumer's module type, so it loads in both ESM and CommonJS repos.

Surfaced by trakli/webui#103. That repo pins the action at @main, so merging
here turns its validate check green on a re-run, with no change needed there.

The action wrote commitlint.config.js with module.exports. In a repository
whose package.json sets "type": "module", node treats that file as an ES
module and the run fails with "module is not defined in ES module scope".
A .cjs file stays CommonJS regardless of the consumer's module type, so the
config loads in both module and commonjs repositories.
@sourceant

sourceant Bot commented Jul 14, 2026

Copy link
Copy Markdown

Code Review Summary

This PR fixes a runtime crash in ESM-based repositories by renaming the generated commitlint.config.js to commitlint.config.cjs. This forces Node.js to interpret the file as CommonJS, avoiding scope errors when module.exports is used.

🚀 Key Improvements

  • Fixed compatibility with repositories using "type": "module" in package.json.
  • Synchronized the npx commitlint command to point to the new filename.

@sourceant sourceant Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review complete. No specific code suggestions were generated. See the overview comment for a summary.

@nfebe
nfebe merged commit c2125d6 into main Jul 14, 2026
@nfebe
nfebe deleted the fix/commitlint-config-esm-repos branch July 14, 2026 10:38
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.

1 participant