len4o17
len4o17

Reputation: 53

Issue with CommitLint: "Please add rules to your `commitlint.config.js`" error despite having rules in my configuration file

I am implementing a commit linting hook for a team project. I successfully installed Husky and moved on to configuring my CommitLint. Wanting to use the basic conventional commits convention, I installed the following packages. Here is my package.json:

devDependencies": {
    "@commitlint/cli": "^17.6.1",
    "@commitlint/config-conventional": "^17.6.1",
    "@types/lodash": "^4.14.192",
    "@typescript-eslint/eslint-plugin": "^5.53.0",
    "@typescript-eslint/parser": "^5.53.0",
    "eslint": "^8.35.0",
    "eslint-config-prettier": "^8.6.0",
    "eslint-plugin-prettier": "^4.2.1",
    "husky": "^8.0.0",
    "prettier": "^2.8.4"
  }

And these are the contents of my commitlint.config.js:

const Configuration = {
  /*
   * Resolve and load @commitlint/config-conventional from node_modules.
   * Referenced packages must be installed
   */
  extends: ["@commitlint/config-conventional"],
};

export default Configuration;

I've also tried using the following command from the docs for initializing the config file, but to no avail. echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js

My commitlint hook looks like this:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx commitlint --edit $1

I am at my wits' end. The config file is clearly exporting something in both cases, but I am still getting the error to add rules. The husky folder is in a subdirectory of the git repo, if that could cause issues.

Besides using the echo command to create a config file, I also tried to use both the typescript and the javascript full configurations, presented in the commitlint docs. I've also tried pasting the full configuration from here https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/index.js

Nothing works so far.

Upvotes: 4

Views: 6122

Answers (2)

qi xiaodong
qi xiaodong

Reputation: 1

This is my dependency package

"devDependencies": {
    "@commitlint/cli": "^19.7.1",
    "@commitlint/config-conventional": "^19.7.1",
    "@types/node": "18.18.13",
    "commitizen": "^4.3.1",
    "cz-conventional-changelog": "^3.3.0",
    "husky": "^9.1.7"
  }

You can try changing the file name of commitilint.config. js to commitilint.config. cjs

// commitlint.config.cjs

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

Please also note that the file encoding is utf-8

Upvotes: 0

lars
lars

Reputation: 417

I had the same issue and was able to overcome it by adding this section to my package.json, which configures commitlint to use config-conventional.

"commitlint": {
  "extends": [
    "@commitlint/config-conventional"
  ]
},

Also ensure that you installed both dev dependencies.

"@commitlint/cli": "18.0.0",
"@commitlint/config-conventional": "18.0.0",

You can find this also in the commitlint projects package.json. ;- ) https://github.com/conventional-changelog/commitlint/blob/master/package.json

Upvotes: 7

Related Questions