lerna ERR! TypeError: Cannot read property 'version' of undefined
Current Behavior
There are two packages,package-a and package-b.
package-b dependencies package-a,using the Workspace protocol.
package-b
{
"name": "package-b",
"version": "1.0.1",
"dependencies": {
"package-a": "workspace:*"
}
}
Expected Behavior
Run npx lerna publish from-package
Expected successful publish
Steps to Reproduce
$ npx lerna publish from-package
lerna notice cli v5.5.2
lerna info versioning independent
lerna WARN Unable to determine published version, assuming "package-b" unpublished.
Found 1 package to publish:
- package-b => 1.0.1
? Are you sure you want to publish these packages? Yes
lerna info publish Publishing packages to npm...
lerna WARN ENOLICENSE Package package-b is missing a license.
lerna WARN ENOLICENSE One way to fix this is to add a LICENSE.md file to the root of this repository.
lerna WARN ENOLICENSE See https://choosealicense.com for additional guidance.
lerna ERR! TypeError: Cannot read property 'version' of undefined
lerna ERR! at /Users/xxx/node_modules/.pnpm/@[email protected]/node_modules/@lerna/package-graph/index.js:80:37
lerna ERR! at Array.forEach (<anonymous>)
lerna ERR! at /Users/xxx/node_modules/.pnpm/@[email protected]/node_modules/@lerna/package-graph/index.js:60:38
lerna ERR! at Map.forEach (<anonymous>)
lerna ERR! at new PackageGraph (/Users/xxx/node_modules/.pnpm/@[email protected]/node_modules/@lerna/package-graph/index.js:49:10)
lerna ERR! at new QueryGraph (/Users/xxx/node_modules/.pnpm/@[email protected]/node_modules/@lerna/query-graph/query-graph.js:48:18)
lerna ERR! at runTopologically (/Users/xxx/node_modules/.pnpm/@[email protected]/node_modules/@lerna/run-topologically/run-topologically.js:23:17)
lerna ERR! at PublishCommand.topoMapPackages (/Users/xxx/node_modules/.pnpm/@[email protected]/node_modules/@lerna/publish/index.js:639:12)
lerna ERR! lerna Cannot read property 'version' of undefined
Failure Logs / Configuration
lerna.json
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"useWorkspaces": true,
"npmClient": "pnpm",
"version": "independent"
}
Environment
- macOS Monterey 12.5, Apple M1 Pro
- [email protected]
- [email protected]
- [email protected]
We have the same problem. Tested with both lerna version & lerna publish locally and in our bitbucket pipeline.
pnpm -v
7.12.2
pnpm lerna -v
5.6.1
In @lerna/[email protected], depNode is undefined after choosing Yes in terminal when running lerna version. Quick fix for our usecase. We use workspace:* and don't actually publish.
diff --git a/index.js b/index.js
index a22558e5c0b2779ac875d14288f8d67c22889839..8d72a11c870ef9bffd17d2df1f33e12cef1b6cfb 100644
--- a/index.js
+++ b/index.js
@@ -77,7 +77,7 @@ class PackageGraph extends Map {
if (spec === "*" || spec === "^" || spec === "~") {
workspaceAlias = spec;
const prefix = spec === "*" ? "" : spec;
- const version = depNode.version;
+ const version = depNode && depNode.version ? depNode.version : "*";
spec = `${prefix}${version}`;
}
}
I have the same problem too, is there any solution now?
Hi everyone, thank you for your engagement on this issue. It has since been addressed in PR #3358. The problem should be fixed with Lerna version 5.6.2.
Hi everyone, thank you for your engagement on this issue. It has since been addressed in PR #3358. The problem should be fixed with Lerna version 5.6.2.
@fahslaj Thanks. I've tried,the problem has been solved in Lerna version 5.6.2
@fahslaj It reproduces on version 6.0.1 & Yarn 3.2.1 with pnp mode. Should I use version 5 ?
Yeah, I see the same issue on 6.0.5