commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

Cannot find module "@commitlint/config-conventional" when running commintlint globally

Open dexpota opened this issue 5 years ago β€’ 47 comments

Expected Behavior

I installed commitlint and commitlint/config-conventional globally, thus running echo 'hello world' | commitlint under any directory should works.

Current Behavior

The command raises an exception.

/usr/local/lib/node_modules/@commitlint/cli/lib/cli.js:67
                throw err;
                ^

Error: Cannot find module "@commitlint/config-conventional" from "/home/fabrizio"
    at resolveId (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:134:12)
    at resolveConfig (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:111:18)
    at /usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:63:18
    at Array.reduce (<anonymous>)
    at loadExtends (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:61:32)
    at resolveExtends (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:44:17)
    at Object.$If_1 (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/core/lib/load.js:90:46)
    at Object.<anonymous> (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/core/lib/load.js:159:18)
    at <anonymous>

Affected packages

  • [x] cli
  • [x] config-conventional

Steps to Reproduce (for bugs)

  1. npm install -g @commitlint/cli @commitlint/config-conventional
  2. echo "module.exports = {extends: ['@commitlint/config-conventional']};" > ~/.commitlintrc.js
  3. echo 'should fail' | commitlint
commitlint.config.js ```js module.exports = {extends: ['@commitlint/config-conventional']}; ```

Your Environment

Executable Version
commitlint --version 7.5.2
git --version 2.17.1
node --version 8.10.0

dexpota avatar Apr 04 '19 21:04 dexpota

I think commitlint is usually being used on a per project basis. So each project has it's own config. If you want to use it globally like you tried you could use the --config option and try this:

echo 'should fail' | commitlint --config ~/.commitlintrc.js

escapedcat avatar Apr 05 '19 01:04 escapedcat

I tried your solution and is not working, the same exception as before.

From what I understand from issueΒ #123 it should be possible to use commitlint from any directory starting from version 5.0.1.

dexpota avatar Apr 05 '19 12:04 dexpota

we're also running into this issue.

our goal is 0 configuration enforcement of conventional commits in CI --I expected the following to work:

❯ cd $(mktemp -d) && ls -a
.  ..

❯ export CI_COMMIT_MESSAGE='foo: bar'

❯ npx -p @commitlint/config-conventional -p @commitlint/cli -c 'echo $CI_COMMIT_MESSAGE | commitlint -x @commitlint/config-conventional'
npx: installed 137 in 8.51s
/Users/foo/.npm/_npx/6761/lib/node_modules/@commitlint/cli/lib/cli.js:113
	throw err;
	^

Error: Cannot find module "@commitlint/config-conventional" from "/private/var/folders/xr/dxys9d310_s1j3klz_1xwz9jq1qqv5/T/tmp.BsKwQjE1QE"
    at resolveId (/Users/foo/.npm/_npx/6761/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:112:14)
    at resolveConfig (/Users/foo/.npm/_npx/6761/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:92:20)
    at reduce (/Users/foo/.npm/_npx/6761/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:49:20)
    at Array.reduce (<anonymous>)
    at loadExtends (/Users/foo/.npm/_npx/6761/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:47:32)
    at resolveExtends (/Users/foo/.npm/_npx/6761/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:30:19)
    at Object.$If_1 (/Users/foo/.npm/_npx/6761/lib/node_modules/@commitlint/cli/node_modules/@commitlint/load/lib/index.js:69:45)
    at Object.<anonymous> (/Users/foo/.npm/_npx/6761/lib/node_modules/@commitlint/cli/node_modules/@commitlint/load/lib/index.js:142:17)

knksmith57 avatar Apr 09 '19 20:04 knksmith57

@dexpota I just tried this on a clean Ubuntu VM:

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

Output is:

β§—   input: hello world
βœ–   subject may not be empty [subject-empty]
βœ–   type may not be empty [type-empty]
βœ–   found 2 problems, 0 warnings 
    (Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint )
cat ~/.commitlintrc.js
module.exports = {extends: ['@commitlint/config-conventional']}

I'm sorry, but I can't reproduce your issue.

This issue is related to https://github.com/conventional-changelog/commitlint/issues/126#issuecomment-345508707

escapedcat avatar Apr 12 '19 06:04 escapedcat

Which version of Ubuntu are you using? I tried with Ubuntu 18.04 on a VM created with vagrant and I am having the same problem.

/usr/local/lib/node_modules/@commitlint/cli/lib/cli.js:113
        throw err;
        ^

Error: Cannot find module "@commitlint/config-conventional" from "/home/vagrant"
    at resolveId (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:112:14)
    at resolveConfig (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:92:20)
    at reduce (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:49:20)
    at Array.reduce (<anonymous>)
    at loadExtends (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:47:32)
    at resolveExtends (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:30:19)
    at Object.$If_1 (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/load/lib/index.js:69:45)
    at Object.<anonymous> (/usr/local/lib/node_modules/@commitlint/cli/node_modules/@commitlint/load/lib/index.js:142:17)
    at <anonymous>

Here more information about the tool versions:

vagrant@ubuntu-bionic:~$ npm --version                                                      
3.5.2
vagrant@ubuntu-bionic:~$ node --version
v8.10.0
vagrant@ubuntu-bionic:~$ git --version
git version 2.17.1
vagrant@ubuntu-bionic:~$ commitlint --version
7.5.2

and these are the steps to recreate the VM using vagrant:

vagrant init ubuntu/bionic64
vagrant up
vagran ssh

dexpota avatar Apr 12 '19 07:04 dexpota

Alright, it's the node version! I used Ubuntu 18.04 with latest npm/node. Sorry for saying clean. I should have mentioned that. Is it possible for you to update the node version? I'm not sure how much effort we would put in to make this case work (again) in v8.

escapedcat avatar Apr 12 '19 09:04 escapedcat

I tried with node version 10.15.3 and npm version 6.4.1 and now it's working.

dexpota avatar Apr 13 '19 09:04 dexpota

to provide some color --it looks like our issue is slightly different from the one reported here.

I can deterministically reproduce the module resolution failure on both node 8.x and 10.x when using npx to fetch and run commitlint; however, I cannot reproduce on either 8.x or 10.x if the modules are first installed globally.

works with npm i -g
npm i -g @commitlint/config-conventional @commitlint/cli
echo 'hello world' \
  | commitlint -x @commitlint/config-conventional

❯ docker run --rm -i --entrypoint sh node:8.15.1 <<'EOT'
npm i -g @commitlint/config-conventional @commitlint/cli
echo 'hello world' \
  | commitlint -x @commitlint/config-conventional
EOT
/usr/local/bin/commitlint -> /usr/local/lib/node_modules/@commitlint/cli/lib/cli.js
+ @commitlint/[email protected]
+ @commitlint/[email protected]
added 137 packages from 64 contributors in 9.439s

β§—   input: hello world
βœ–   subject may not be empty [subject-empty]
βœ–   type may not be empty [type-empty]
βœ–   found 2 problems, 0 warnings
    (Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint )
❯ docker run --rm -i --entrypoint sh node:10.15.3 <<'EOT'
npm i -g @commitlint/config-conventional @commitlint/cli
echo 'hello world' \
  | commitlint -x @commitlint/config-conventional
EOT
/usr/local/bin/commitlint -> /usr/local/lib/node_modules/@commitlint/cli/lib/cli.js
+ @commitlint/[email protected]
+ @commitlint/[email protected]
added 137 packages from 64 contributors in 10.263s

β§—   input: hello world
βœ–   subject may not be empty [subject-empty]
βœ–   type may not be empty [type-empty]
βœ–   found 2 problems, 0 warnings
    (Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint )
fails with npx -p
echo 'hello world' \
  | npx \
    -p @commitlint/config-conventional \
    -p @commitlint/cli \
  commitlint -x @commitlint/config-conventional

❯ docker run --rm -i --entrypoint sh node:8.15.1 <<'EOT'
echo 'hello world' \
  | npx \
    -p @commitlint/config-conventional \
    -p @commitlint/cli \
  commitlint -x @commitlint/config-conventional
EOT
npx: installed 137 in 9.894s
/root/.npm/_npx/7/lib/node_modules/@commitlint/cli/lib/cli.js:113
	throw err;
	^

Error: Cannot find module "@commitlint/config-conventional" from "/"
    at resolveId (/root/.npm/_npx/7/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:112:14)
    at resolveConfig (/root/.npm/_npx/7/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:92:20)
    at reduce (/root/.npm/_npx/7/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:49:20)
    at Array.reduce (<anonymous>)
    at loadExtends (/root/.npm/_npx/7/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:47:32)
    at resolveExtends (/root/.npm/_npx/7/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:30:19)
    at Object.$If_1 (/root/.npm/_npx/7/lib/node_modules/@commitlint/cli/node_modules/@commitlint/load/lib/index.js:69:45)
    at Object.<anonymous> (/root/.npm/_npx/7/lib/node_modules/@commitlint/cli/node_modules/@commitlint/load/lib/index.js:142:17)
    at <anonymous>
❯ docker run --rm -i --entrypoint sh node:10.15.3 <<'EOT'
echo 'hello world' \
  | npx \
    -p @commitlint/config-conventional \
    -p @commitlint/cli \
  commitlint -x @commitlint/config-conventional
EOT
npx: installed 137 in 8.683s
/root/.npm/_npx/9/lib/node_modules/@commitlint/cli/lib/cli.js:113
	throw err;
	^

Error: Cannot find module "@commitlint/config-conventional" from "/"
    at resolveId (/root/.npm/_npx/9/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:112:14)
    at resolveConfig (/root/.npm/_npx/9/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:92:20)
    at reduce (/root/.npm/_npx/9/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:49:20)
    at Array.reduce (<anonymous>)
    at loadExtends (/root/.npm/_npx/9/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:47:32)
    at resolveExtends (/root/.npm/_npx/9/lib/node_modules/@commitlint/cli/node_modules/@commitlint/resolve-extends/lib/index.js:30:19)
    at Object.$If_1 (/root/.npm/_npx/9/lib/node_modules/@commitlint/cli/node_modules/@commitlint/load/lib/index.js:69:45)
    at Object.<anonymous> (/root/.npm/_npx/9/lib/node_modules/@commitlint/cli/node_modules/@commitlint/load/lib/index.js:142:17)

At this point I'm thinking this is either an issue with @commitlint/resolve-extends or a bug in npx.

knksmith57 avatar Apr 13 '19 19:04 knksmith57

I did some digging too because I really really want to implement zero-config and the GitHub Action πŸ˜… There is actually a chain of dependencies, working together making global imports work, here it goes:

  1. @commitlint/cli - requests resolved configuration from @commitlint/resolve-extends
  2. @commitlint/resolve-extends - fetches configuration based on module ids with resolve-from and/or resolve-global
  3. resolve-global - needs a place to look at for global modules, so it requests a path to this with global-dirs
  4. global-dirs - currently has an issue where it resolves the symlink origin of the installed Node, instead of resolving to the proper global folder.

There we go, that's our issue too. I tried adding a 3rd fallback in @commitlint/resolve-extends to look into the hardcoded /usr/local/lib/node_modules folder, and it worked.

I'm not sure if we should drop or swap out resolve-global, because it's a nice library and has support for both Yarn and NPM. Maybe we can pitch in with Sindre to get this fixed? There are some great developers who have documented a lot in that issue, so it's up for grabs to fix it I guess.

For now, I can confidently add the "bug" label to this until that issue is resolved.

byCedric avatar Apr 26 '19 23:04 byCedric

Little status update: a PR to fix the underlying issue as described above is merged. Now we have to wait for a release and then we can test if it's still broken or not. πŸ˜„

To quote Sindre (maker of the package):

I'll do a new release once the other open PRs are merged.

byCedric avatar Apr 30 '19 22:04 byCedric

New 1.0.0 release of the global-dirs is released! I'll work on this issue tonight (CEST), will check if the 1.0.0 is included in our semver range and test if it still persists after that.

byCedric avatar May 02 '19 11:05 byCedric

I've tested this one, and unfortunately [email protected] isn't here (yet). Right now, resolve-global needs to be updated. Luckily, I created a PR for this, let's hope it's merged (& released) soon! πŸ˜„

byCedric avatar May 02 '19 19:05 byCedric

Quick status update, Yarn still has some issues with global-dirs. Stay tuned for more updates πŸ˜„

byCedric avatar May 06 '19 21:05 byCedric

@byCedric Any new updates on this? Still tuned here.

nfantone avatar Oct 01 '19 04:10 nfantone

Unfortunately, it's still blocked by https://github.com/sindresorhus/global-dirs/issues/13. 😞 Apparently, its kind of a hard issue to solve. If it's not solvable in that library, we might have to rethink if we can solve this issue without this library.

But that's a decision where also @marionebl and @escapedcat must be involved.

byCedric avatar Oct 01 '19 18:10 byCedric

Yup, it would be great to use it like @knksmith57 mentioned in the second example. So having only commitlint.config.js file with

module.exports = {extends: ['@commitlint/config-conventional']}

and running:

npx -p @commitlint/config-conventional -p @commitlint/cli -c 'echo "test" |commitlint'

So the project can either have it own rules/config (if it's included in package.json) or use default by only including the basic config file (eg. for non-nodejs projects)

fastman avatar Nov 18 '19 10:11 fastman

hey brother, When can this problem be solved. Are there other solutions thx!!!

Kcaby avatar Mar 18 '20 09:03 Kcaby

@Linyutau there's no timeline. This is more or less blocked by https://github.com/sindresorhus/global-dirs/issues/13

escapedcat avatar Mar 18 '20 11:03 escapedcat

A bit unrelated, but in case it helps somebody: This error also occurs without having commitlint installed globally: if you have your commitlint.config.js a level above where your package.json is, the config is still found, but the OPs error occurs. For me, it was a simple mistake and when I copied the config to the same level as the package.json, it worked fine again.

Lagily avatar Mar 27 '20 14:03 Lagily

i run into the same bug under macOS. Is there any workaround to get it work as global installation?

mseele avatar Jun 09 '20 15:06 mseele

Guys, here the same problem happened when installing globally.

I solved it by adding the full path to the @commitlint/config-conventional folder in my commitlint.config.js in each project.

Example: module-yarn-global-commitlint

This is far from the best way, but it resolved.

paesrafael avatar Jul 11 '20 19:07 paesrafael

@paesrafael guessing you don’t work with any others as that’s only gonna work for your computer.

OmgImAlexis avatar Jul 11 '20 23:07 OmgImAlexis

I was experiencing the same issue see https://github.com/conventional-changelog/commitlint/issues/847.

However, I recently upgraded to node 10, and will try to retest this in the next couple of days since it seems that fixed the issue for some people in this thread.

CrispyDrone avatar Jul 18 '20 22:07 CrispyDrone

@paesrafael guessing you don’t work with any others as that’s only gonna work for your computer.

One year later, I am experiencing same issue with node v14.17.3 and npm 6.14.13 and globally installed commitlint. His reply actually helped me to focus on actual work

nikoladsp avatar Aug 19 '21 09:08 nikoladsp

Can confirm that it does not work.

fwiw semantic-release’s plugins work as expected with npx. Knowing nothing about the implementation at least it suggests that this isn't a fundamental problem.

npx \
  --yes \
  --package [email protected] \
  --package @semantic-release/[email protected] \
  -- \
    semantic-release

mamachanko avatar Nov 24 '21 09:11 mamachanko

I got it to work by installing packages not-exactly-globally.

You install npm packages to the user's home directory, e.g. by following these instructions.

I have seen it work with nvm, but apparently that does not work for everyone (see @OmgImAlexis' comment below).

Kehrlann avatar Dec 13 '21 14:12 Kehrlann

@Kehrlann I have this issue with nvm lol

OmgImAlexis avatar Dec 13 '21 19:12 OmgImAlexis

@Kehrlann I have this issue with nvm lol

@OmgImAlexis which node version?

mamachanko avatar Dec 15 '21 07:12 mamachanko

I got it to work by installing packages not-exactly-globally.

You install npm packages to the user's home directory, e.g. by following these instructions.

I have seen it work with nvm, but apparently that does not work for everyone (see @OmgImAlexis' comment below).

Thanks, that helped me!

y0zg avatar Dec 29 '21 13:12 y0zg

For some reason, I had created the config file outside my working directory, one level back, then commitlint when trying to find the module, it didn't find it because node_modules was one level inside, I changed the config inside and it worked fine.

dbrab avatar Feb 26 '22 22:02 dbrab