Open thelinuxlich opened 6 months ago
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
Was it a monorepo?
Yeah just a single repository with a single package.json
file. No nx
or lerna
involved.
So you had dependencies with workspace on the root folder and it still worked?
Yes, that‘s correct.
Oh wait, you used pnpm dlx
Yes, its the same as pnpx
. As stated above I have installed commitizen
as a project devDependency and not as a global package.
@thelinuxlich Did you manage to get it up and running? If so, I guess we should close this issue. 😄
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 https://github.com/pnpm/pnpm/issues/7738#issuecomment-1982910416), 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.
This is caused by the pnpm workspace root check.
A viable workaround:
pnpm config set ignore-workspace-root-check true
pnpm dlx commitizen init cz-conventional-changelog --pnpm --save-dev --save-exact
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.
@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:
pnpm add cz-conventional-changelog -w -D
.czrc
file
{
"path": "cz-conventional-changelog"
}
Or config in package.json
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
}
It does the same as
commitizen init
Running
commitizen init cz-conventional-changelog --pnpm --save-dev --save-exact
gives me this output: