nodejs/node · error · GypError

Dependency '%s' not found while trying to load target %s

Error message

Dependency '%s' not found while trying to load target %s

What it means

When constructing the target-level dependency graph (input.py ~1950), each entry in a target's 'dependencies' list must resolve to an already-built DependencyGraphNode. If dependency_nodes.get(dependency) is None, the referenced qualified target was never registered, so gyp cannot wire the edge and raises GypError naming both the missing dependency and the target that referenced it.

Source

Thrown at tools/gyp/pylib/gyp/input.py:1950

    dependency_nodes = {}
    for target, spec in targets.items():
        if target not in dependency_nodes:
            dependency_nodes[target] = DependencyGraphNode(target)

    # Set up the dependency links.  Targets that have no dependencies are treated
    # as dependent on root_node.
    root_node = DependencyGraphNode(None)
    for target, spec in targets.items():
        target_node = dependency_nodes[target]
        dependencies = spec.get("dependencies")
        if not dependencies:
            target_node.dependencies = [root_node]
            root_node.dependents.append(target_node)
        else:
            for dependency in dependencies:
                dependency_node = dependency_nodes.get(dependency)
                if not dependency_node:
                    raise GypError(
                        "Dependency '%s' not found while "
                        "trying to load target %s" % (dependency, target)
                    )
                target_node.dependencies.append(dependency_node)
                dependency_node.dependents.append(target_node)

    flat_list = root_node.FlattenToList()

    # If there's anything left unvisited, there must be a circular dependency
    # (cycle).
    if len(flat_list) != len(targets):
        if not root_node.dependents:
            # If all targets have dependencies, add the first target as a dependent
            # of root_node so that the cycle can be discovered from root_node.
            target = next(iter(targets))
            target_node = dependency_nodes[target]
            target_node.dependencies.append(root_node)
            root_node.dependents.append(target_node)

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Verify the dependency string exactly matches 'path/to.gyp:target_name' (correct relative path, correct target_name).
  2. Confirm the referenced target actually exists and is not inside a false conditional.
  3. Ensure the .gyp file declaring the target is included (directly or transitively) by the build.
  4. Check for toolset mismatches if using multi-toolset builds.

Example fix

// before
'dependencies': ['../util/util.gyp:utillib']  // target is actually 'util_lib'

// after
'dependencies': ['../util/util.gyp:util_lib']
Defensive patterns

Strategy: validation

Validate before calling

known = set(targets)
for t, spec in targets.items():
    for d in spec.get('dependencies', []):
        assert d in known, 'unresolvable dependency %r in %r' % (d, t)

Type guard

def deps_resolve(deps, known): return all(d in known for d in deps)

Try / catch

try:
    gyp.main(args)
except gyp.input.GypError as e:
    if 'not found while trying to load target' in str(e): print('Check dependency spelling/path'); raise

Prevention

When it happens

Trigger: For target T with spec['dependencies'] containing D, dependency_nodes has no key D after all targets were loaded. Occurs right before FlattenToList, so it is a hard load-time failure.

Common situations: Typo in a dependency qualified target name; referring to path/to.gyp:target where target does not exist in that file; wrong build-file path component (relative path mismatch); dependency on a target guarded by a conditional that evaluated false; .gyp file not actually included into the build.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/1887590772272819. Report an issue: GitHub.