commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

fix: fails to load config file on Node v24.0.0

Open sodle-splunk opened this issue 7 months ago • 8 comments

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

sodle-splunk avatar May 07 '25 19:05 sodle-splunk

Thanks for the heads up. Is there something that could be done on our side? If yes, happy for a PR

escapedcat avatar May 08 '25 02:05 escapedcat

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 🤔

sodle-splunk avatar May 08 '25 03:05 sodle-splunk

Weird. Created a new release from latest master, give that a try.

escapedcat avatar May 08 '25 03:05 escapedcat

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 barebones package.json with the project type set to module.

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.

sodle avatar May 08 '25 18:05 sodle

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?

escapedcat avatar May 12 '25 10:05 escapedcat

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

sodle avatar May 13 '25 14:05 sodle

Wanna create a PR for the docs?

escapedcat avatar May 14 '25 03:05 escapedcat

Done. https://github.com/conventional-changelog/commitlint/pull/4406

sodle avatar May 14 '25 13:05 sodle