{"record":{"id":"0b6a6d817e6609c3","repo":"nodejs/node","slug":"missing-target-name-field-in-target","errorCode":null,"errorMessage":"Missing 'target_name' field in target.","messagePattern":"Missing 'target_name' field in target\\.","errorType":"exception","errorClass":"GypError","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/input.py","lineNumber":1842,"sourceCode":"\n        If |include_shared_libraries| is False, the resulting dependencies will not\n        include shared_library targets that are linked into this target.\n        \"\"\"\n        if dependencies is None:\n            # Using a list to get ordered output and a set to do fast \"is it\n            # already added\" checks.\n            dependencies = OrderedSet()\n\n        # Check for None, corresponding to the root node.\n        if self.ref is None:\n            return dependencies\n\n        # It's kind of sucky that |targets| has to be passed into this function,\n        # but that's presently the easiest way to access the target dicts so that\n        # this function can find target types.\n\n        if \"target_name\" not in targets[self.ref]:\n            raise GypError(\"Missing 'target_name' field in target.\")\n\n        if \"type\" not in targets[self.ref]:\n            raise GypError(\n                \"Missing 'type' field in target %s\" % targets[self.ref][\"target_name\"]\n            )\n\n        target_type = targets[self.ref][\"type\"]\n\n        is_linkable = target_type in linkable_types\n\n        if initial and not is_linkable:\n            # If this is the first target being examined and it's not linkable,\n            # return an empty list of link dependencies, because the link\n            # dependencies are intended to apply to the target itself (initial is\n            # True) and this target won't be linked.\n            return dependencies\n\n        # Don't traverse 'none' targets if explicitly excluded.","sourceCodeStart":1824,"sourceCodeEnd":1860,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/input.py#L1824-L1860","documentation":"While traversing the target dependency graph to compute link/dependency sets (DependencyGraphNode), every referenced target dict MUST contain a 'target_name' key. The guard at input.py:1842 inside the link-dependency computation aborts when targets[self.ref] has no 'target_name', because the node cannot be meaningfully identified or reported without it.","triggerScenarios":"During dependency-set computation, targets[self.ref] (the spec dict for the node currently being examined) lacks the 'target_name' key. This is reached for both initial and non-initial nodes that participate in dependency walking.","commonSituations":"A programmatic .gyp generator or a hand-written target dict that omits target_name; a malformed/partial target produced by a bad merge or variable expansion; a third-party .gypi include that defines an incomplete target skeleton; corruption from an aborted dict-merge pass.","solutions":["Add 'target_name' to every target dict in the offending .gyp file's targets array.","Locate the target via the partial context in the error/stack trace and inspect targets[self.ref] keys.","Run gyp with --check to surface the offending file before link-time.","If generated programmatically, audit the generator to always emit target_name."],"exampleFix":"// before\n{ 'type': 'static_library', 'sources': ['a.cc'] }\n\n// after\n{ 'target_name': 'foo', 'type': 'static_library', 'sources': ['a.cc'] }","handlingStrategy":"validation","validationCode":"for t in spec.get('targets', []):\n    assert 'target_name' in t, 'target missing target_name: %r' % t\n","typeGuard":"def has_target_name(t): return isinstance(t, dict) and 'target_name' in t","tryCatchPattern":"try:\n    gyp.main(args)\nexcept gyp.input.GypError as e:\n    if 'target_name' in str(e): print('Add target_name to the offending target'); raise","preventionTips":["Always emit target_name when generating .gyp targets.","Run gyp --check to validate structure early.","Validate target dicts in a pre-commit lint."],"tags":["gyp","target-spec","validation","build-config"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}