leoforfree / cz-customizable

A standalone commit message helper or customizable commitizen adapter for https://github.com/commitizen/cz-cli
MIT License
603 stars 201 forks source link

[Error] unable to find configuration file (using it in non JS Project) #234

Open lamyergeier opened 4 months ago

lamyergeier commented 4 months ago

Install

$ npm i -g commitizen cz-customizable

$ file /home/lamy/opt/.nvm/versions/node/v20.7.0/lib/node_modules/cz-customizable/
/home/lamy/opt/.nvm/versions/node/v20.7.0/lib/node_modules/cz-customizable/: directory

$ command cat ~/.czrc 
{"path":"/mnt/Data/opt/.nvm/versions/node/v20.7.0/lib/node_modules/cz-customizable"}

My repository

Note: I have added cz-config.js to repository head

$ la
total 24K
755 drwxr-xr-x. 7 lamy lamy 4.0K 2024-04-28 01:21 .git
644 -rw-r--r--. 1 lamy lamy   17 2024-04-27 00:33 .gitignore
644 -rw-r--r--. 1 lamy lamy 2.3K 2024-04-28 01:19 Podcast.json
644 -rw-r--r--. 1 lamy lamy   57 2024-04-27 23:46 Podcast_tag.txt
644 -rw-r--r--. 1 lamy lamy 2.5K 2024-04-28 01:17 cz-config.js

Error

$ cz
cz-cli@4.3.0, cz-customizable@7.0.0

Unable to find a configuration file. Please refer to documentation to learn how to set up: https://github.com/leonardoanalista/cz-customizable#steps "
Cannot read properties of null (reading 'subjectLimit')
$ cz-customizable
cz-customizable standalone version
Unable to find a configuration file. Please refer to documentation to learn how to set up: https://github.com/leonardoanalista/cz-customizable#steps "
/mnt/Data/opt/.nvm/versions/node/v20.7.0/lib/node_modules/cz-customizable/index.js:16
    config.subjectLimit = config.subjectLimit || 100;
                                 ^

TypeError: Cannot read properties of null (reading 'subjectLimit')
    at Object.prompter (/mnt/Data/opt/.nvm/versions/node/v20.7.0/lib/node_modules/cz-customizable/index.js:16:34)
    at Object.<anonymous> (/mnt/Data/opt/.nvm/versions/node/v20.7.0/lib/node_modules/cz-customizable/standalone.js:19:5)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47

Node.js v20.7.0

Note

I get the same error when I put cz-config.js inside ${HOME} instead of the repository (as above).

pokeyaro commented 3 months ago

Maybe it's not “subjectLimit“ problem, you can try the following steps.

  1. If the content starts with module.exports = { ..., it is recommended to change cz-config.js to .cjs
  2. In addition, configuration items can be changed in package.json:
{
  ...,
  "config": {
    "commitizen": {
      "path": "node_modules/cz-customizable"
    },
    "cz-customizable": {
      "config": "your-path/cz-config.cjs"
    }
  }
}