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

PNPM support is broken #994

Open
thelinuxlich opened this issue May 20, 2024 · 11 comments
Open

PNPM support is broken #994

thelinuxlich opened this issue May 20, 2024 · 11 comments

Comments

@thelinuxlich
Copy link

Running commitizen init cz-conventional-changelog --pnpm --save-dev --save-exact gives me this output:

Attempting to initialize using the npm package cz-conventional-changelog
npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "workspace:": workspace:*

npm ERR! A complete log of this run can be found in: /home/thelinuxlich/.npm/_logs/2024-05-20T13_29_22_244Z-debug-0.log
Error: Command failed: npm install cz-conventional-changelog --save-dev
npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "workspace:": workspace:*

npm ERR! A complete log of this run can be found in: /home/thelinuxlich/.npm/_logs/2024-05-20T13_29_22_244Z-debug-0.log

    at checkExecSyncError (node:child_process:890:11)
    at Object.execSync (node:child_process:962:15)
    at init (/usr/local/lib/node_modules/commitizen/dist/commitizen/init.js:1017:28)
    at Object.bootstrap (/usr/local/lib/node_modules/commitizen/dist/cli/commitizen.js:34:30)
    at Object.<anonymous> (/usr/local/lib/node_modules/commitizen/bin/commitizen.js:2:38)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12) {
  status: 1,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 6e 70 6d 20 45 52 52 21 20 63 6f 64 65 20 45 55 4e 53 55 50 50 4f 52 54 45 44 50 52 4f 54 4f 43 4f 4c 0a 6e 70 6d 20 45 52 52 21 20 55 6e 73 75 70 70 ... 162 more bytes>
  ],
  pid: 9285,
  stdout: <Buffer >,
  stderr: <Buffer 6e 70 6d 20 45 52 52 21 20 63 6f 64 65 20 45 55 4e 53 55 50 50 4f 52 54 45 44 50 52 4f 54 4f 43 4f 4c 0a 6e 70 6d 20 45 52 52 21 20 55 6e 73 75 70 70 ... 162 more bytes>
}
@devtobi
Copy link

devtobi commented May 27, 2024

I installed commitizen locally inside the repository and then ran the initialization with: pnpm dlx commitizen init cz-conventional-changelog --pnpm --save-dev --save-exact and it worked just fine.

pnpm version: 9.1.3

@thelinuxlich
Copy link
Author

Was it a monorepo?

@devtobi
Copy link

devtobi commented May 27, 2024

Yeah just a single repository with a single package.json file. No nxor lerna involved.

@thelinuxlich
Copy link
Author

So you had dependencies with workspace on the root folder and it still worked?

@devtobi
Copy link

devtobi commented May 27, 2024

Yes, that‘s correct.

@thelinuxlich
Copy link
Author

Oh wait, you used pnpm dlx

@devtobi
Copy link

devtobi commented May 27, 2024

Yes, its the same as pnpx. As stated above I have installed commitizen as a project devDependency and not as a global package.

@devtobi
Copy link

devtobi commented May 30, 2024

@thelinuxlich Did you manage to get it up and running? If so, I guess we should close this issue. 😄

@ianlet
Copy link

ianlet commented Sep 23, 2024

Neither of the global commitizen and local pnpm dlx commitizen commands seem to work for me. I also try to run it at the root of pnpm workspace (no nx, lerna, etc.)

$ pnpm dlx commitizen init cz-conventional-changelog --pnpm --save-dev --save-exact
Attempting to initialize using the npm package cz-conventional-changelog
Error: Command failed: pnpm add cz-conventional-changelog --save-dev
    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at checkExecSyncError (node:child_process:890:11)
    at Object.execSync (node:child_process:962:15)
    at init (/home/ian/.cache/pnpm/dlx/n6ucavohe6yfg2cemixhqeizvi/1921f4c6513-112422/node_modules/.pnpm/commitizen@4.3.0_@types+node@22.5.5_typescript@5.6.2/node_modules/commitizen/dist/commitizen/init.js:1024:28)
    at Object.bootstrap (/home/ian/.cache/pnpm/dlx/n6ucavohe6yfg2cemixhqeizvi/1921f4c6513-112422/node_modules/.pnpm/commitizen@4.3.0_@types+node@22.5.5_typescript@5.6.2/node_modules/commitizen/dist/cli/commitizen.js:30:30)
    at Object.<anonymous> (/home/ian/.cache/pnpm/dlx/n6ucavohe6yfg2cemixhqeizvi/1921f4c6513-112422/node_modules/.pnpm/commitizen@4.3.0_@types+node@22.5.5_typescript@5.6.2/node_modules/commitizen/bin/commitizen.js:2:38)
    at Module._compile (node:internal/modules/cjs/loader:1378:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
    at Module.load (node:internal/modules/cjs/loader:1212:32) {
  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: 1125243,
  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 >
}

It seems to be caused by this: when we try to install a package at the root of a pnpm workspace it requires us to add the -w|--workspace-root flag to make sure we actually intended to install it there.

For example:

pnpm add -D commitizen
 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.

When I disable this check by adding ignore-workspace-root-check=true in .npmrc (see pnpm/pnpm#7738 (comment)), the error goes away and the init script works as expected.

It would be great to be able to better support this case instead of crashing. I could have a look at it if you want.

@Mirasaki
Copy link

This is caused by the pnpm workspace root check.

A viable workaround:

  1. pnpm config set ignore-workspace-root-check true
  2. pnpm dlx commitizen init cz-conventional-changelog --pnpm --save-dev --save-exact
  3. pnpm config set ignore-workspace-root-check false

For the maintainers, as Ianlet has pointed out - this is caused by pnpm rejecting package installations to a monorepo root by default. The -w or --ignore-workspace-root-check needs to be added to the pnpm add command.

I think the following is contradicting, and might be confusing the package/repository maintainers.

thelinuxlich commented on May 27
Was it a monorepo?

devtobi commented on May 27
Yeah just a single repository with a single package.json file. No nxor lerna involved.

thelinuxlich commented on May 27
So you had dependencies with workspace on the root folder and it still worked?

devtobi commented on May 28
Yes, that‘s correct.

Tobi states they only have a single package.json file in their repository, but also that they're using pnpm workspaces. If workspaces were actually in use, there would be multiple package.json files. The errors seems to occur regardless of whether or not the pnpm workspace protocol ("workspace:*" ) is used in the monorepo root package.json dependencies, indicating the root source of this error is having a pnpm-workspace.yaml file in the project root - which would make sense.

@iamyoki
Copy link

iamyoki commented Sep 27, 2024

@Mirasaki Thank you, it works, but end of the work pnpm config delete ignore-workspace-root-check true is better.

Another workaround is by manually install:

  1. pnpm add cz-conventional-changelog -w -D
  2. add a .czrc file
{
  "path": "cz-conventional-changelog"
}

Or config in package.json

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

It does the same as commitizen init

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

No branches or pull requests

5 participants