nodejs/node · error · GypError

Missing 'type' field in target %s

Error message

Missing 'type' field in target %s

What it means

After confirming a target has 'target_name', the dependency-walk guard at input.py:1845 requires a 'type' field to classify the target (linkable vs not, via linkable_types). Without 'type' the graph cannot decide link behavior, so gyp raises GypError naming the target.

Source

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

        """
        if dependencies is None:
            # Using a list to get ordered output and a set to do fast "is it
            # already added" checks.
            dependencies = OrderedSet()

        # Check for None, corresponding to the root node.
        if self.ref is None:
            return dependencies

        # It's kind of sucky that |targets| has to be passed into this function,
        # but that's presently the easiest way to access the target dicts so that
        # this function can find target types.

        if "target_name" not in targets[self.ref]:
            raise GypError("Missing 'target_name' field in target.")

        if "type" not in targets[self.ref]:
            raise GypError(
                "Missing 'type' field in target %s" % targets[self.ref]["target_name"]
            )

        target_type = targets[self.ref]["type"]

        is_linkable = target_type in linkable_types

        if initial and not is_linkable:
            # If this is the first target being examined and it's not linkable,
            # return an empty list of link dependencies, because the link
            # dependencies are intended to apply to the target itself (initial is
            # True) and this target won't be linked.
            return dependencies

        # Don't traverse 'none' targets if explicitly excluded.
        if target_type == "none" and not targets[self.ref].get(
            "dependencies_traverse", True
        ):

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Add a 'type' field set to one of the VALID_TARGET_TYPES (executable, static_library, shared_library, loadable_module, mac_kernel_extension, none, windows_driver).
  2. Check for stray conditionals or includes that delete 'type'.
  3. Validate the .gyp file with gyp --check.

Example fix

// before
{ 'target_name': 'foo', 'sources': ['a.cc'] }

// after
{ 'target_name': 'foo', 'type': 'static_library', 'sources': ['a.cc'] }
Defensive patterns

Strategy: validation

Validate before calling

VALID = {'executable','static_library','shared_library','loadable_module','mac_kernel_extension','none','windows_driver'}
for t in spec.get('targets', []):
    assert t.get('type') in VALID, 'bad/missing type in %s' % t.get('target_name')

Type guard

def valid_type(t): return t.get('type') in {'executable','static_library','shared_library','loadable_module','mac_kernel_extension','none','windows_driver'}

Try / catch

try:
    gyp.main(args)
except gyp.input.GypError as e:
    if "Missing 'type' field" in str(e): print('Add a valid type field'); raise

Prevention

When it happens

Trigger: targets[self.ref] contains 'target_name' but is missing the 'type' key, hit while computing link dependencies for a node.

Common situations: Target dict with target_name but a forgotten/typo'd type field; conditional that strips type; include file that partially overrides a target; migration from an older gyp that defaulted type.

Related errors


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