nodejs/node · error · GypError

Found wildcard in {dependency_key} of {target} referring to

Error message

Found wildcard in {dependency_key} of {target} referring to same build file

What it means

GYP permits wildcard dependencies (a target/toolset component equal to '*') to pull in every target from a given .gyp file. This error fires when such a wildcard resolves to the SAME .gyp file that the depending target lives in. The library forbids it because at minimum the depending target would end up depending on itself, which is an unsatisfiable cycle, so gyp.common.ParseQualifiedTarget is used to detect target=='*' or toolset=='*' with dependency_build_file==target_build_file.

Source

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

            # Loop this way instead of "for dependency in" or "for index in range"
            # because the dependencies list will be modified within the loop body.
            index = 0
            while index < len(dependencies):
                (
                    dependency_build_file,
                    dependency_target,
                    dependency_toolset,
                ) = gyp.common.ParseQualifiedTarget(dependencies[index])
                if dependency_target != "*" and dependency_toolset != "*":
                    # Not a wildcard.  Keep it moving.
                    index = index + 1
                    continue

                if dependency_build_file == target_build_file:
                    # It's an error for a target to depend on all other targets in
                    # the same file, because a target cannot depend on itself.
                    raise GypError(
                        "Found wildcard in "
                        + dependency_key
                        + " of "
                        + target
                        + " referring to same build file"
                    )

                # Take the wildcard out and adjust the index so that the next
                # dependency in the list will be processed the next time through the
                # loop.
                del dependencies[index]
                index = index - 1

                # Loop through the targets in the other build file, adding them to
                # this target's list of dependencies in place of the removed
                # wildcard.
                dependency_target_dicts = data[dependency_build_file]["targets"]
                for dependency_target_dict in dependency_target_dicts:

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Replace the wildcard with an explicit list of target names from that .gyp file, excluding the depending target itself (e.g. ['mylib.gyp:helper','mylib.gyp:util']).
  2. If you truly need everything, move the depending target into a different .gyp file so the wildcard no longer points at the same build file.
  3. Remove the self-referential wildcard entry entirely and depend only on the specific targets you need.
  4. Run gyp with --check / enable debug output to confirm which dependency_key (dependencies / dependencies_original / hard_dependencies) holds the offending wildcard.

Example fix

// before (inside a target in mylib.gyp)
'dependencies': ['mylib.gyp:*']

// after
'dependencies': ['mylib.gyp:helper', 'mylib.gyp:util']
Defensive patterns

Strategy: validation

Validate before calling

import gyp.common
for dep in spec.get('dependencies', []):
    bf, tgt, ts = gyp.common.ParseQualifiedTarget(dep)
    if (tgt == '*' or ts == '*') and bf == target_build_file:
        raise SystemExit('Reject same-file wildcard dep: %r' % dep)

Try / catch

try:
    gyp.main(args)
except gyp.input.GypError as e:
    if 'referring to same build file' in str(e):
        print('Fix wildcard dependency in', target); raise

Prevention

When it happens

Trigger: A target's 'dependencies' array contains an entry whose target or toolset part is '*' (e.g. 'foo.gyp:*', 'foo.gyp:bar/*', or the ':*' shorthand) and the build-file portion equals the current target's own .gyp file (target_build_file). The check at input.py:1551 runs during wildcard dependency expansion in the early load pass.

Common situations: Copy-pasting a wildcard dep like 'mylib.gyp:*' into a target that itself resides in mylib.gyp; renaming/moving a .gyp file so a previously-external wildcard now resolves locally; using ':*' shorthand inside the same file intending 'all other targets'; bulk-importing dependencies via a generator that emits '*' for convenience.

Related errors


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