#37213·nx

ProjectGraphBuilder drops an edge recorded on a workspace file when another project already recorded one to the same target

Author: spichenCreated Sep 28, 2026Updated Sep 28, 2026

Current Behavior

When a plugin's createDependencies gives two projects a static edge to the same target, and both edges name the same workspace-level file (one that belongs to no project) as sourceFile, only the first edge survives. The second project gets no edge at all.

ProjectGraphBuilder.addDependency checks for an existing edge on the file by target and type. For a workspace file, though, the stored dependency is a [source, target, type] tuple, and fileDataDepTarget / fileDataDepType ignore the source. So a second project's edge to the same target counts as a duplicate of the first project's edge.

This came up with @nxlv/python's new external nodes: every member of a uv workspace recorded its package edges on the one root uv.lock, and every member after the first lost the edges it shared with an earlier one (lucasvieirasilva/nx-plugins#368 works around it with implicit edges).

Expected Behavior

Each project keeps its own edge. For a workspace file, the duplicate check should compare the source as well as the target and type.

Steps to Reproduce

With nx and @nx/devkit 23.2.1 installed:

javascript
const { DependencyType } = require('@nx/devkit');
const { ProjectGraphBuilder } = require('nx/src/project-graph/project-graph-builder');

const nonProjectFiles = [{ file: 'shared.lock', hash: 'x' }];
const projectFileMap = {
  a: [{ file: 'a/package.json', hash: '1' }],
  b: [{ file: 'b/package.json', hash: '2' }],
};
const builder = new ProjectGraphBuilder(undefined, projectFileMap, nonProjectFiles);
builder.addNode({ name: 'a', type: 'lib', data: { root: 'a' } });
builder.addNode({ name: 'b', type: 'lib', data: { root: 'b' } });
builder.addExternalNode({ type: 'npm', name: 'npm:lodash', data: { version: '4.17.21', packageName: 'lodash' } });

builder.addDependency('a', 'npm:lodash', DependencyType.static, 'shared.lock');
builder.addDependency('b', 'npm:lodash', DependencyType.static, 'shared.lock');

const graph = builder.getUpdatedProjectGraph();
console.log('a ->', graph.dependencies.a.map((d) => d.target));
console.log('b ->', graph.dependencies.b.map((d) => d.target));
console.log('shared.lock deps:', JSON.stringify(nonProjectFiles[0].deps));

Output:

a -> [ 'npm:lodash' ]
b -> []
shared.lock deps: [["a","npm:lodash","static"]]

The check is in packages/nx/src/project-graph/project-graph-builder.ts (addDependency):

typescript
if (
  !fileData.deps.find(
    (t) => fileDataDepTarget(t) === target && fileDataDepType(t) === type
  )
) {

For a workspace file it would also need to compare t[0] with source.

Nx Report

Nx 23.2.1, @nx/devkit 23.2.1, Node 24.13.1, macOS.

Failure Logs

None; the edge is dropped silently.