Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commitizen init doesn't work with pnpm #858

Closed
sunnz opened this issue Nov 10, 2021 · 4 comments · Fixed by #915
Closed

commitizen init doesn't work with pnpm #858

sunnz opened this issue Nov 10, 2021 · 4 comments · Fixed by #915
Labels

Comments

@sunnz
Copy link

sunnz commented Nov 10, 2021

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/[email protected]/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/[email protected]/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/[email protected]/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>
}
jimthedev pushed a commit that referenced this issue Jan 19, 2023
pnpm reuses options available for npm, except `force`

re: #893, re #858
@github-actions
Copy link

🎉 This issue has been resolved in version 4.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jhubbardsf
Copy link

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/[email protected]/node_modules/commitizen/dist/commitizen/init.js:1024:28)
    at Object.bootstrap (/Users/josh/Engineering/SvelteKit/lively/node_modules/.pnpm/[email protected]/node_modules/commitizen/dist/cli/commitizen.js:30:30)
    at Object.<anonymous> (/Users/josh/Engineering/SvelteKit/lively/node_modules/.pnpm/[email protected]/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
Copy link

xsu1010 commented Feb 28, 2023

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/[email protected]/node_modules/commitizen/dist/commitizen/init.js:1024:28)
    at Object.bootstrap (/Users/josh/Engineering/SvelteKit/lively/node_modules/.pnpm/[email protected]/node_modules/commitizen/dist/cli/commitizen.js:30:30)
    at Object.<anonymous> (/Users/josh/Engineering/SvelteKit/lively/node_modules/.pnpm/[email protected]/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
Copy link

q11070 commented Oct 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants