fix: fails to load config file on Node v24.0.0
Steps to Reproduce
Place the following in `commitlint.config.js`:
export default { extends: ['@commitlint/config-conventional'] };
Run:
echo 'feat: example commit' | commitlint
Current Behavior
Commitlint fails to load the config file:
â§— input: feat: example commit
✖ Please add rules to your `commitlint.config.js`
- Getting started guide: https://commitlint.js.org/guides/getting-started
- Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/src/index.ts [empty-rules]
✖ found 1 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
Expected Behavior
Commitlint should run and accept this commit
Affected packages
- [x] cli
- [x] core
- [ ] prompt
- [ ] config-angular
Possible Solution
No response
Context
This issue appeared when Node 24 was released yesterday, it works fine on v22 and v23.
This is an issue because commitlint-pre-commit-hook always uses the latest version of Node. I will be filing a ticket with that project as well, recommending that they use the LTS version instead.
commitlint --version
@commitlint/[email protected]
git --version
git version 2.39.5 (Apple Git-154)
node --version
v24.0.0
Thanks for the heads up. Is there something that could be done on our side? If yes, happy for a PR
I can look into it, but JavaScript isn't my forte so I'm not sure how much help I'll be.
I believe the fix would ultimately need to be in this repo though.
So far I've only been able to repro it with the latest commitlint build from NPM, was struggling to repro with a build from source 🤔
Weird. Created a new release from latest master, give that a try.
Switching to my personal GitHub account for this effort.
I'm able to reproduce the issue on Node 24 using either the latest NPM build, or a manual build from the master branch, when both of the following are true:
- The config file is named
commitlint.config.js. - The project does not contain a
package.json(i.e., it is not a NodeJS project).
I have found two valid workarounds:
- Rename the config file to
commitlint.config.mjs, which explicitly marks it as an ES module. - Run
npm init es6, which adds a barebonespackage.jsonwith the project type set tomodule.
It appears something has changed with how imports work in v24, though I'm not exactly sure what. Glancing at the source code for loading configs, I think this might ultimately be a bug in cosmiconfig rather than commitlint.
Rename the config file to commitlint.config.mjs, which explicitly marks it as an ES module.
Maybe we should add a warning regarding node v24 into the docs for now?
Yeah I think that makes sense. Basically if you're using v24, you need to have a package.json, or else your config has to be called *.mjs instead of *.js
Wanna create a PR for the docs?
Done. https://github.com/conventional-changelog/commitlint/pull/4406