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

nx release version incorrectly resolves some dependency versions #28695

Open
1 of 4 tasks
xalechez opened this issue Oct 30, 2024 · 7 comments
Open
1 of 4 tasks

nx release version incorrectly resolves some dependency versions #28695

xalechez opened this issue Oct 30, 2024 · 7 comments

Comments

@xalechez
Copy link

xalechez commented Oct 30, 2024

Current Behavior

Info about the workspace:

  • 17 npm packages. Independent versioning via git tags (using generic names as they're private)
  • Recently migrated from Lerna
  • Using pnpm workspaces and workspace protocol
  • nx.json (fragment):
  "targetDefaults": {
    "nx-release-publish": {
      "options": {
        "packageRoot": "dist/packages/{projectName}"
      }
    }
  },
  "release": {
    "projects": ["packages/*"],
    "projectsRelationship": "independent",
    "changelog": {
      "projectChangelogs": {
        "file": false,
        "createRelease": {
          "provider": "github-enterprise-server",
          "hostname": "our.ghe.server"
        }
      }
    },
    "version": {
      "preVersionCommand": "pnpm nx run-many -t experimental-build",
      "generatorOptions": {
        "updateDependents": "auto",
        "specifierSource": "conventional-commits",
        "currentVersionResolver": "git-tag",
        "packageRoot": "dist/packages/{projectName}"
      }
    }
  },

When running nx release version --dry-run --specifier patch

  • Package A is versioned correctly from git tag and provided specifier
 NX   Running release version for project: package-a

package-a 🔍 Reading data for package "package-a" from dist/packages/package-a/package.json
package-a 📄 Resolved the current version as 3.0.1 from git tag "package-a@3.0.1".
package-a 📄 Using the provided version specifier "patch".
package-a ✍️  New version 3.0.2 written to dist/packages/package-a/package.json
  • All other packages are versioned correctly as well
  • package.json for Package A is updated correctly
UPDATE dist/packages/package-a/package.json [dry-run]

    "name": "package-a",
-   "version": "0.0.0",
+   "version": "3.0.2",
    "description": "package-a",

      "json-cycle": "^1.3.0",
-     "package-b": "workspace:*",
-     "package-c": "workspace:*",
+     "package-b": "7.0.13",
+     "package-c": "4.0.18",
      "uuid": "^9.0.1"
  • package.json for Package D is updated incorrectly
UPDATE dist/packages/package-d/package.json [dry-run]

    "name": "package-d",
-   "version": "0.0.0",
+   "version": "2.2.3",
    "description": "package-d ",

      "md5": "^2.2.1",
-     "package-b": "workspace:*",
-     "package-a": "workspace:*",
-     "package-c": "workspace:*",
+     "package-b": "7.0.13",
+     "package-a": "0.0.1", 🔴 (should be 3.0.2)
+     "package-c": "4.0.18",
      "uuid": "^9.0.1"

My main assumption is that package.json of Package D is updated before Package A, resulting in the version of Package A to be resolved to 0.0.0. There're no cycles in the graph, so I think that the execution order of versioning is wrong.

Expected Behavior

I'd expect package-a version inside package-d package.json file to be 3.0.2. Either Nx should write versions first and then handle dependencies, or execute versioning in correct order aligning with the project graph

GitHub Repo

No response

Steps to Reproduce

  1. Initialise package-based repo with multiple npm packages
  2. Add pnpm workspaces
  3. Use workspace protocol to link dependent packages
  4. Run nx release version --dry-run --specifier patch

Nx Report

NX Report complete - copy this into the issue template

Node : 18.20.4
OS : darwin-arm64
Native Target : aarch64-macos
pnpm : 9.12.0

nx (global) : 19.6.4
nx : 20.0.6
@nx/js : 20.0.6
@nx/jest : 20.0.6
@nx/eslint : 20.0.6
@nx/eslint-plugin : 20.0.6
typescript : 5.6.3

Registered Plugins:
@nx/eslint/plugin
@nx/jest/plugin

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

This error repeats on 19.8.3 which could mean it's not related to #28380

@xalechez xalechez changed the title nx release version incorrectly resolves dependency version with pnpm workspaces nx release version incorrectly resolves some dependency versions Oct 30, 2024
@vctqs1anz
Copy link

+1 encountered same issue on the new packages

@xalechez
Copy link
Author

xalechez commented Nov 4, 2024

Tried to use preserveLocalDependencyProtocols and pnpm publish, now I'm seeing empty pnpm publish error: without any message or stacktrace

Maybe I'm missing something... @JamesHenry do you by any chance have any link/tutorial about how to correctly set up Nx Release with:

  • pnpm workspaces
  • workspace protocol for local dependencies
  • no versioning in source control - every package version is 0.0.0 locally, and is expected to be resolved from git tags before publish both for the package itself and its workspace dependencies

It used to work correctly with npm and versioning inside source control

@JamesHenry
Copy link
Collaborator

@xalechez Did you try running the publish with --verbose? Please do if not, and if that doesn't change anything, it might be good to try patching node_modules/@nx/js/src/executors/release-publish/release-publish.impl.js to add some more logging (and please let me know what you needed to add to get more information and we can improve the error handling in this case). You should be able to find the relevant catch block for the publishing where the pnpm publish error is coming from

@fabioatcorreia
Copy link
Contributor

Also found a related problem where nx release version does not correctly update the dependencies version when using independent versioning.

Example:
Package A depends on Package B
Package A depends on Package C
Package B and C were updated and a new version was created

Result: Package A dependencies only has Package B updated while Package C version remains the same

For reference, I've tested with NX version 19 and it works as expected, so, it seems to be something introduced in version 20.

@xalechez
Copy link
Author

xalechez commented Dec 2, 2024

With Nx 20.1.4 it accidentally got better. Now instead of ~15 broken links in my monorepo I have only one. Does anyone know what change could cause this improvement?

@xalechez
Copy link
Author

xalechez commented Dec 2, 2024

So the problem is that the one broken link doesn't appear in projectVersionData when releaseVersion() is called programmatically. All other parts of projectVersionData are correct.

When I run a project graph, both via CLI and programmatically, it identifies this dependency correctly.

Even more, when I put a debugger on @nx/js/src/generators/release-version/release-version.js line 396, at first iterations localPackageDependencies contains 6 local links for the source package, including the one in question, but later (somewhere after ~9 iterations) it mysteriously disappears, and localPackageDependencies[sourcePackageName] contains only 5 local dependencies instead of 6.

This is a very weird behaviour which I'll try to debug further (which is quite complex because of a lot of nested loops), but it looks like a race condition which for some reason makes this link to be filtered out of the version data after something else changes in the background (I assume Nx writes version data in parallel as I see rawVersionSpec changes between the iterations first from workspace:^ to ^0.0.0 or ^0.0.1 (don't understand why it varies between different packages) and then to the actual versions resolved from git tags)

I would be very grateful for any more advise on this issue from the team as it's currently a large blocker for us adopting Nx

@virtuallyunknown
Copy link

Greetings. Apologies if this is not the most relevant place to put this info, so I will keep it ultra short.

If you are getting pnpm publish error messages followed by some seemingly random output, it might be related to pnpm version 9.14.1, and upgrading to 9.15 fixes the issue.

pnpm/pnpm#8788

For some weird reason, this is not an issue with nx 19, but after I upgraded to 20 I started getting it. Anyway, have a nice day.

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

No branches or pull requests

5 participants