{"record":{"id":"a2eb6398d270271b","repo":"nodejs/node","slug":"missing-type-field-for-target-s-in-s","errorCode":null,"errorMessage":"Missing type field for target %s in %s.","messagePattern":"Missing type field for target (.+?) in (.+?)\\.","errorType":"exception","errorClass":"GypError","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/generator/msvs.py","lineNumber":1152,"sourceCode":"        An integer, the configuration type.\n    \"\"\"\n    try:\n        config_type = {\n            \"executable\": \"1\",  # .exe\n            \"shared_library\": \"2\",  # .dll\n            \"loadable_module\": \"2\",  # .dll\n            \"static_library\": \"4\",  # .lib\n            \"windows_driver\": \"5\",  # .sys\n            \"none\": \"10\",  # Utility type\n        }[spec[\"type\"]]\n    except KeyError:\n        if spec.get(\"type\"):\n            raise GypError(\n                \"Target type %s is not a valid target type for \"\n                \"target %s in %s.\" % (spec[\"type\"], spec[\"target_name\"], build_file)\n            )\n        else:\n            raise GypError(\n                \"Missing type field for target %s in %s.\"\n                % (spec[\"target_name\"], build_file)\n            )\n    return config_type\n\n\ndef _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config):\n    \"\"\"Adds a configuration to the MSVS project.\n\n    Many settings in a vcproj file are specific to a configuration.  This\n    function the main part of the vcproj file that's configuration specific.\n\n    Arguments:\n      p: The target project being generated.\n      spec: The target dictionary containing the properties of the target.\n      config_type: The configuration type, a number as defined by Microsoft.\n      config_name: The name of the configuration.\n      config: The dictionary that defines the special processing to be done","sourceCodeStart":1134,"sourceCodeEnd":1170,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/generator/msvs.py#L1134-L1170","documentation":"Raised as a GypError when a target has no 'type' field at all. This is the companion to the invalid-type error: the dict lookup raises KeyError, and because spec.get('type') is falsy (missing or None), the 'Missing type field' branch is taken instead of the invalid-type branch. A target without a type cannot be mapped to any MSVS project kind.","triggerScenarios":"A target dictionary in a .gyp file that omits the 'type' key entirely, or sets it to None/empty. The KeyError at msvs.py:1138 is caught and spec.get('type') evaluates falsy, hitting msvs.py:1153.","commonSituations":"A newly added target where 'type' was forgotten; a target constructed via a template/include that failed to set type; accidental deletion of the type line during a refactor.","solutions":["Add a 'type' key to the target with a valid value (e.g. 'static_library', 'executable', 'none').","If the target is templated, ensure the template/conditions always produce a concrete type.","Run gyp's check mode to catch missing required fields early."],"exampleFix":"// before\n'targets': [{ 'target_name': 'foo', 'sources': ['foo.cc'] }]\n// after\n'targets': [{ 'target_name': 'foo', 'type': 'static_library', 'sources': ['foo.cc'] }]","handlingStrategy":"validation","validationCode":"for t in build_file_data.get('targets', []):\n    if not t.get('type'):\n        raise ValueError(f\"target {t.get('target_name')} missing 'type'\")","typeGuard":"def target_has_type(t) -> bool:\n    return isinstance(t, dict) and bool(t.get('type'))","tryCatchPattern":null,"preventionTips":["Treat 'type' as a required field in target templates.","Add a CI check that every target declares a type."],"tags":["gyp","msvs","target-type","missing-field","windows"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}