commitlint: Cannot find module "@commitlint/config-conventional" when running commintlint globally
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
- cli
- config-conventional
Steps to Reproduce (for bugs)
npm install -g @commitlint/cli @commitlint/config-conventional
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > ~/.commitlintrc.js
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 |
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 35
- Comments: 47 (16 by maintainers)
Commits related to this issue
- chore: make husky work on macOS commitlint has some issue working with globally installed npm packages. See https://github.com/conventional-changelog/commitlint/issues/613 for more details. The work... — committed to asap-projects/asap-common by abdes 2 years ago
- chore: make husky work on macOS commitlint has some issue working with globally installed npm packages. See conventional-changelog/commitlint#613 for more details. The workaround is to not set the c... — committed to abdes/asap by abdes 2 years ago
- feat(config): check if the commit message is a conventional commit - For the husky v.8 not use the `.huskyrc` file for set the configuration. Set the configuration inside the `.husky` folder, in the ... — committed to beatrizsmerino/vue-todolist by beatrizsmerino 2 years ago
- feat: add commitlint to installation Note that in order to use local .commitlinrc.yml files which extend the `@commitlint/config-conventional` settings, we need to explicitly set NODE_PATH. Without d... — committed to adamliter/conf by adamliter 10 months ago
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:Workaround for those in the same case as me, manually include the rules from your chosen config in your
commitlint.config.js
config file.Here are the rules for
@commitlint/config-conventional
in YAML:.commitlintrc.yaml
@dexpota I just tried this on a clean Ubuntu VM:
Output is:
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
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
fails with
npx -p
At this point I’m thinking this is either an issue with
@commitlint/resolve-extends
or a bug innpx
.@paesrafael guessing you don’t work with any others as that’s only gonna work for your computer.
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:
This is far from the best way, but it resolved.
With @commitlint/cli and @commitlint/config-conventional installed globally, on Linux, I got it working like this:
echo "hello world" | commitlint -g ~/.commitlintrc.js -x $(npm root -g)/@commitlint/config-conventional
we’re also running into this issue.
our goal is 0 configuration enforcement of conventional commits in CI --I expected the following to work:
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:
@commitlint/cli
- requests resolved configuration from@commitlint/resolve-extends
@commitlint/resolve-extends
- fetches configuration based on module ids withresolve-from
and/orresolve-global
resolve-global
- needs a place to look at for global modules, so it requests a path to this withglobal-dirs
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.
I was also facing this issue when using
node
installed by Homebrew on a Mac (which gets installed to/opt/homebrew
on Macs with the newer ARM-based chips). The suggestion of settingNODE_PATH
worked for me. I just addedexport NODE_PATH=$(npm root -g)
to my.profile
file.Just set
NODE_PATH
, in my case: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.
This might be a bit late, but here is my setup:
@commitlint/cli
and@commitlint/config-conventional
globally via npm..zsh-aliases
for example.Now you can use commitlint with
config-conventional
from anywhere, without having to create a.commitlintrc.js
in every project.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
I tried with node version
10.15.3
and npm version6.4.1
and now it’s working.I am also having the same problem. I would like to use commitlint on a non-node.js project (with no package.json).
Reproduce
Error:
@mamachanko mentioned semantic-release’s plugin system works well. I would like to add that textlint’s plugin system also works:
Thanks, that helped me!
No sure if pnpm ever worked with this or not but I know that there is at least one PR related to pnpm. Would be great to have someone who could take care of checking and testing pnpm support.
Here’s how I managed to arrive at a zero config solution (workaround):
Requires an intermediary temp file, which I didn’t manage to get rid of…
Just to add to @politician’s great comment, the command then becomes something like:
npx commitlint --from main --to HEAD --verbose --config commitlintrc.yaml
.I have to say that I’m somewhat shocked that this was so difficult to find. Does nobody outside of the JS ecosystem use commitlint?
@Kehrlann I have this issue with nvm lol
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).
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.Yup, it would be great to use it like @knksmith57 mentioned in the second example. So having only
commitlint.config.js
file withand running:
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)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.
I’ve tested this one, and unfortunately
global-dirs@1.0.0
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! 😄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):