commitizen / cz-cli

The commitizen command line utility. #BlackLivesMatter
http://commitizen.github.io/cz-cli/
MIT License
16.89k stars 552 forks source link

commitizen init doesn't work with pnpm #858

Closed sunnz closed 1 year ago

sunnz commented 3 years ago

I had run the commitizen init cz-conventional-changelog --save-dev --save-exact command as per README, but it doesn't work, see a copy and paste of the error from commitizen at the end.

Suggestion: when there exists a pnpm-lock.yaml file, use pnpm instead of npm.

Here's my workaround:

pnpm add -D -E cz-conventional-changelog

Then add this block to the package.json file:

  "config": {
    "commitizen": {
      "path": "cz-conventional-changelog"
    }
  },

The cz command works as usual from this point.

Error from commitizen init cz-conventional-changelog --save-dev --save-exact:

Attempting to initialize using the npm package cz-conventional-changelog
npm WARN old lockfile 
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile 
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile 
npm ERR! code EINVALIDPACKAGENAME
npm ERR! Invalid package name ".pnpm": name cannot start with a period

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/sunnz/.npm/_logs/2021-11-10T12_28_43_823Z-debug.log
Error: Command failed: npm install cz-conventional-changelog --save-dev
npm WARN old lockfile 
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile 
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile 
npm ERR! code EINVALIDPACKAGENAME
npm ERR! Invalid package name ".pnpm": name cannot start with a period

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/sunnz/.npm/_logs/2021-11-10T12_28_43_823Z-debug.log

    at checkExecSyncError (node:child_process:826:11)
    at Object.execSync (node:child_process:900:15)
    at init (/Users/sunnz/Library/pnpm/nodejs/16.11.1/pnpm-global/5/node_modules/.pnpm/commitizen@4.2.4/node_modules/commitizen/dist/commitizen/init.js:1017:28)
    at Object.bootstrap (/Users/sunnz/Library/pnpm/nodejs/16.11.1/pnpm-global/5/node_modules/.pnpm/commitizen@4.2.4/node_modules/commitizen/dist/cli/commitizen.js:34:30)
    at Object.<anonymous> (/Users/sunnz/Library/pnpm/nodejs/16.11.1/pnpm-global/5/node_modules/.pnpm/commitizen@4.2.4/node_modules/commitizen/bin/commitizen.js:2:38)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  status: 1,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 6e 70 6d 20 57 41 52 4e 20 6f 6c 64 20 6c 6f 63 6b 66 69 6c 65 20 0a 6e 70 6d 20 57 41 52 4e 20 6f 6c 64 20 6c 6f 63 6b 66 69 6c 65 20 54 68 65 20 70 ... 491 more bytes>
  ],
  pid: 55718,
  stdout: <Buffer >,
  stderr: <Buffer 6e 70 6d 20 57 41 52 4e 20 6f 6c 64 20 6c 6f 63 6b 66 69 6c 65 20 0a 6e 70 6d 20 57 41 52 4e 20 6f 6c 64 20 6c 6f 63 6b 66 69 6c 65 20 54 68 65 20 70 ... 491 more bytes>
}
github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 4.3.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

jhubbardsf commented 1 year ago

I'm still getting an error with pnpm on 4.3.0.

Attempting to initialize using the npm package cz-conventional-changelog
Error: Command failed: pnpm add cz-conventional-changelog --save-dev
    at checkExecSyncError (node:child_process:871:11)
    at Object.execSync (node:child_process:943:15)
    at init (/Users/josh/Engineering/SvelteKit/lively/node_modules/.pnpm/commitizen@4.3.0/node_modules/commitizen/dist/commitizen/init.js:1024:28)
    at Object.bootstrap (/Users/josh/Engineering/SvelteKit/lively/node_modules/.pnpm/commitizen@4.3.0/node_modules/commitizen/dist/cli/commitizen.js:30:30)
    at Object.<anonymous> (/Users/josh/Engineering/SvelteKit/lively/node_modules/.pnpm/commitizen@4.3.0/node_modules/commitizen/bin/commitizen.js:2:38)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12) {
  status: 1,
  signal: null,
  output: [
    null,
    <Buffer e2 80 89 45 52 52 5f 50 4e 50 4d 5f 41 44 44 49 4e 47 5f 54 4f 5f 52 4f 4f 54 e2 80 89 20 52 75 6e 6e 69 6e 67 20 74 68 69 73 20 63 6f 6d 6d 61 6e 64 ... 302 more bytes>,
    <Buffer >
  ],
  pid: 40756,
  stdout: <Buffer e2 80 89 45 52 52 5f 50 4e 50 4d 5f 41 44 44 49 4e 47 5f 54 4f 5f 52 4f 4f 54 e2 80 89 20 52 75 6e 6e 69 6e 67 20 74 68 69 73 20 63 6f 6d 6d 61 6e 64 ... 302 more bytes>,
  stderr: <Buffer >
}
xsu1010 commented 1 year ago

I'm still getting an error with pnpm on 4.3.0.

Attempting to initialize using the npm package cz-conventional-changelog
Error: Command failed: pnpm add cz-conventional-changelog --save-dev
    at checkExecSyncError (node:child_process:871:11)
    at Object.execSync (node:child_process:943:15)
    at init (/Users/josh/Engineering/SvelteKit/lively/node_modules/.pnpm/commitizen@4.3.0/node_modules/commitizen/dist/commitizen/init.js:1024:28)
    at Object.bootstrap (/Users/josh/Engineering/SvelteKit/lively/node_modules/.pnpm/commitizen@4.3.0/node_modules/commitizen/dist/cli/commitizen.js:30:30)
    at Object.<anonymous> (/Users/josh/Engineering/SvelteKit/lively/node_modules/.pnpm/commitizen@4.3.0/node_modules/commitizen/bin/commitizen.js:2:38)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12) {
  status: 1,
  signal: null,
  output: [
    null,
    <Buffer e2 80 89 45 52 52 5f 50 4e 50 4d 5f 41 44 44 49 4e 47 5f 54 4f 5f 52 4f 4f 54 e2 80 89 20 52 75 6e 6e 69 6e 67 20 74 68 69 73 20 63 6f 6d 6d 61 6e 64 ... 302 more bytes>,
    <Buffer >
  ],
  pid: 40756,
  stdout: <Buffer e2 80 89 45 52 52 5f 50 4e 50 4d 5f 41 44 44 49 4e 47 5f 54 4f 5f 52 4f 4f 54 e2 80 89 20 52 75 6e 6e 69 6e 67 20 74 68 69 73 20 63 6f 6d 6d 61 6e 64 ... 302 more bytes>,
  stderr: <Buffer >
}

FWIW, I had this same error when trying to initialize Commitizen on a pnpm workspace.

You'll understand why it crashes if you try to run pnpm add cz-conventional-changelog --save-dev manually: it complains about installing a package to the workspace root.

❯ pnpm add cz-conventional-changelog --save-dev
 ERR_PNPM_ADDING_TO_ROOT  Running this command will add the dependency to the workspace root, which might not be what you want - if you really meant it, make it explicit by running this command again with the -w flag (or --workspace-root). If you don't want to see this warning anymore, you may set the ignore-workspace-root-check setting to true.

A workaround for this was, indeed, to set the ignore-workspace-root-check setting to true:

pnpm config set ignore-workspace-root-check true

Commitizen now initializes without any errors.

q11070 commented 3 weeks ago

Tried this step but it still doesn't work. Anybody got it working?

Hey, the Google Gemini just produced this answer and it works perfectly well !!!

pnpm commitizen init cz-conventional-changelog --pnpm --save-dev --save-exact