commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

Using config example gives error running 19.0.3

Open nkukard opened this issue 11 months ago • 22 comments

Steps to Reproduce

  1. Install commitlint and set up config (ref https://commitlint.js.org/reference/configuration.html)

npm install -g @commitlint/cli @commitlint/config-conventional
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js

  1. Run commitlint

Current Behavior

Results in ...


@commitlint/[email protected]
file:///usr/local/lib/node_modules/@commitlint/cli/lib/cli.js:129
        throw err;
        ^
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/usr/local/lib/node_modules/@commitlint/config-conventional' is not supported resolving ES modules imported from /usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js
Did you mean to import "/usr/local/lib/node_modules/@commitlint/config-conventional/lib/index.js"?
    at finalizeResolution (node:internal/modules/esm/resolve:257:11)
    at moduleResolve (node:internal/modules/esm/resolve:908:10)
    at defaultResolve (node:internal/modules/esm/resolve:1131:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
    at ModuleLoader.import (node:internal/modules/esm/loader:322:34)
    at importModuleDynamically (node:internal/modules/esm/translators:159:35)
    at importModuleDynamicallyCallback (node:internal/modules/esm/utils:207:14)
    at dynamicImport (file:///usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:21:88) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///usr/local/lib/node_modules/@commitlint/config-conventional'
}
Node.js v21.6.2

Expected Behavior

Before 19.0.0 it resulted in ...

@commitlint/[email protected]
96⧗   input: test: testing something
97✔   found 0 problems, 0 warnings
98= = = = = = = = = = = = = = = = = = = = = = = = = = = = =
99### TEST PASSED   (commitlint): Valid commit message passed
100### TEST START    (commitlint): Testing invalid commit message
101[main 393de5d] invalid commit
102 Date: Thu Feb 22 05:44:52 2024 +0000
103 1 file changed, 1 insertion(+), 1 deletion(-)

Affected packages

  • [X] cli
  • [ ] core
  • [ ] prompt
  • [ ] config-angular

Possible Solution

No response

Context

I'm running CI/CD pipelines with many of my software projects and this was picked up in our commitlint job test.

commitlint --version

@commitlint/[email protected]

git --version

v2.44.0

node --version

21.6.2 (fails on 18 & 20 that I test too)

nkukard avatar Feb 29 '24 17:02 nkukard

I tried this locally and it's working:

Screenshot 2024-02-29 at 20 36 34

I also setup a simple GitHub Action and I'm unable to reproduce the issue:

image

https://github.com/marcalexiei/commitlint-playground/actions/runs/8101865722/job/22143073353

marcalexiei avatar Feb 29 '24 20:02 marcalexiei

@marcalexiei have you tried giving it an input that does conform to the format? I am experiencing a similar issue. https://github.com/ItsSunnyMonster/ruxel/actions/runs/8092061505/job/22112127600?pr=37

ItsSunnyMonster avatar Mar 01 '24 06:03 ItsSunnyMonster

have you tried giving it an input that does conform to the format?

It works: https://github.com/marcalexiei/commitlint-playground/actions/runs/8108167213/job/22160890870


In your package.json you are using v18 packages

https://github.com/ItsSunnyMonster/ruxel/blob/9709f3bdc30843d887146ae046d1cef583365f63/package.json#L3-L5

while on your run you GitHub action run you are installing commitlint@latest. commitlint@latest is an alias for commitlint/cli so I think you got a version mismatch. Could you try using packages all v19 packages?

image

marcalexiei avatar Mar 01 '24 08:03 marcalexiei

Here is how to reproduce the issue I'm reporting...

docker run  -it --rm alpine  /bin/sh

apk add npm git
npm install -g @commitlint/cli @commitlint/config-conventional
mkdir test
cd test
git init
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
echo "test" > test.txt
git add test.txt
git commit -m "hello world"
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
commitlint --to HEAD

Here is the last few commands output... Screenshot_20240306_084251

nkukard avatar Mar 06 '24 08:03 nkukard

Did you try latest https://github.com/conventional-changelog/commitlint/releases/tag/v19.0.3?

Global installation usage should have been fixed in v19.0.1.

JounQin avatar Mar 08 '24 05:03 JounQin

Did you try latest https://github.com/conventional-changelog/commitlint/releases/tag/v19.0.3?

Global installation usage should have been fixed in v19.0.1.

Yes, this was done 2 days ago. You can reproduce it right now following the above instructions.

nkukard avatar Mar 08 '24 06:03 nkukard

@nkukard I can't reproduce it with the issue steps.

JounQin avatar Mar 08 '24 06:03 JounQin

@nkukard I can't reproduce it with the issue steps.

Did you try the docker container reproducer and commands I pasted?

This is the official alpine image, I can't see how it cannot be reproducible.

Screenshot_20240308_063514

Screenshot_20240308_063532

Screenshot_20240308_063634

nkukard avatar Mar 08 '24 06:03 nkukard

For clarity sake this is the latest official alpine image...

latest: Pulling from library/alpine
Digest: sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b
Status: Image is up to date for alpine:latest
docker.io/library/alpine:latest

nkukard avatar Mar 08 '24 06:03 nkukard

// test.mjs
import globalDirectory from 'global-directory';

console.log(globalDirectory.npm.packages)
image

It's a upstream issue, please report to https://github.com/sindresorhus/global-directory instead.

And also, I recommend not using global usage any longer.


Besides, it should also occur on v18, doesn't it?

JounQin avatar Mar 08 '24 07:03 JounQin

image

It seems global-modules working as expected in this case, although it's not been maintained for a long time (6 years).

But AFAIK, stylelint is using global-modules instead of global-directory: https://github.com/stylelint/stylelint/blob/d2c8d0dd20924706c3075c9d208234c373a41f42/package.json#L177

@escapedcat Should we change to use global-modules or add it as another fallback?


IMO, we should drop global installation usage in next major version.

JounQin avatar Mar 08 '24 07:03 JounQin

commitlint --to HEAD

I'm very sure many people are using commitlint to lint commits with repositories that are not node based, how would dropping global installation usage affect that?

nkukard avatar Mar 08 '24 07:03 nkukard

@nkukard

OK, interesting, any idea to keep supporting global installation usage easily and maintainable?

JounQin avatar Mar 08 '24 07:03 JounQin

@nkukard

OK, interesting, any idea to keep supporting global installation usage easily and maintainable?

So basically to explain this use case , we have multiple docker containers that run in parallel against MR/PR's being submitted.

Each of the validation containers implements a specific type of check, for instance shellcheck, commitlint ... etc.

The repositories themselves can be anything, from perl libraries, to python libraries, to apps, to distribution packages, Ansible playbooks ... etc.

I'd say there is a valid use case for a global installation, if commitlint were to be installed during this process in the project top folder it would modify the status of the repository unless .node_modules and packages.json were added to .gitignore on every project. To be honest thinking of this makes me shudder.

nkukard avatar Mar 08 '24 07:03 nkukard

@nkukard

I'm not against to support global installation considering the users not using node primarily. I'm just trying to find a good way to support it. As you can see, global-directory works incorrectly and global-modules is really old. I may need to find more other libraries which support global installation usage like eslint, etc.

By the way, did you use commitlint v18 previously as global dependency? And does it work as expected?

JounQin avatar Mar 08 '24 13:03 JounQin

@nkukard

I'm not against to support global installation considering the users not using node primarily. I'm just trying to find a good way to support it. As you can see, global-directory works incorrectly and global-modules is really old. I may need to find more other libraries which support global installation usage like eslint, etc.

No probs.

By the way, did you use commitlint v18 previously as global dependency? And does it work as expected?

My CI/CD pipeline for commitlint started failing when v19 was released. It was working before that with v18.

I'm not sure if maybe another dep may of been updated as I very briefly tried installing <v19.0.0 and it failed in the same way.

I'm currently using export NODE_PATH=/usr/local/lib/node_modules as a workaround in this specific case.

nkukard avatar Mar 08 '24 13:03 nkukard

I checked eslint, it is also not recommended to used as global.

https://eslint.org/docs/latest/use/getting-started#global-install

JounQin avatar Mar 09 '24 03:03 JounQin

I checked eslint, it is also not recommended to used as global.

https://eslint.org/docs/latest/use/getting-started#global-install

I think however there is a difference here. Those using commitlint to lint non JS repositores and those using commitlint to lint JS repositories where commitlint may form part of packages.json?

eslint would be the latter where commitlint could be added to packages.json, the former however would not have a packages.json.

nkukard avatar Mar 09 '24 03:03 nkukard

I mean, I didn't find a good and standard way to resolve global modules and even for npx temporary modules.

JounQin avatar Mar 09 '24 03:03 JounQin

@escapedcat

What's your opinion on

https://github.com/conventional-changelog/commitlint/issues/3947#issuecomment-1985158767

JounQin avatar Mar 11 '24 06:03 JounQin

I'm somewhat torn in between...

Usually I try to find a matching tool in the used env, i.e. in rust I used this before: https://convco.github.io/
But I assume there's no such project for all envs so people are looking for one tool that can be used everywhere. tbh we always had issues with global installations.

Maybe another tool is supporting this case better than commitlint does?

If someone finds a nice and maintainable way to make this work with commitlint that's great.
If we only have a hacky, outdated and hart to maintain way to do it I'd rather avoid this.

Sorry if this not the answer you were looking for.

escapedcat avatar Mar 11 '24 06:03 escapedcat

@nkukard why not use npx commitlint instead of commitlint, after installing without -g? That would be an easy workaround for now.

knocte avatar Mar 20 '24 19:03 knocte