{"record":{"id":"1e4177294e033d1c","repo":"nodejs/node","slug":"target-type-s-is-not-a-valid-target-type-for-targ","errorCode":null,"errorMessage":"Target type %s is not a valid target type for target %s in %s.","messagePattern":"Target type (.+?) is not a valid target type for target (.+?) in (.+?)\\.","errorType":"exception","errorClass":"GypError","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/generator/msvs.py","lineNumber":1147,"sourceCode":"\n    Args:\n        spec: The target dictionary containing the properties of the target.\n        build_file: The path of the gyp file.\n    Returns:\n        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:","sourceCodeStart":1129,"sourceCodeEnd":1165,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/generator/msvs.py#L1129-L1165","documentation":"Raised as a GypError when a target's 'type' field has a value that is not one of the recognized MSVS target types. The recognized types map to Visual Studio configuration types: executable, shared_library, loadable_module, static_library, windows_driver, none. Any other non-empty type value is rejected because there is no MSVS project configuration type to map it to.","triggerScenarios":"A target whose spec['type'] is a non-empty value not in the mapping dict at msvs.py:1138 (e.g. 'loadable_module' misspelled, a custom type like 'bundle', or 'shared_lib'). The KeyError on the dict lookup is caught and, since spec.get('type') is truthy, this branch fires.","commonSituations":"Typo in the type name; using a type valid for another generator but not msvs; a cross-platform target with a platform-specific type that msvs doesn't recognize.","solutions":["Correct the type to one of: executable, shared_library, loadable_module, static_library, windows_driver, none.","If the type is intentionally non-MSVS, gate that target so it is not built under the msvs generator (use conditions).","Check for typos such as 'shared_lib' vs 'shared_library'."],"exampleFix":"// before\n'targets': [{ 'target_name': 'foo', 'type': 'shared_lib' }]\n// after\n'targets': [{ 'target_name': 'foo', 'type': 'shared_library' }]","handlingStrategy":"validation","validationCode":"VALID = {'executable','shared_library','loadable_module','static_library','windows_driver','none'}\nif spec.get('type') and spec['type'] not in VALID:\n    raise ValueError(f\"invalid target type: {spec['type']}\")","typeGuard":"VALID = {'executable','shared_library','loadable_module','static_library','windows_driver','none'}\ndef is_valid_target_type(spec) -> bool:\n    return spec.get('type') in VALID","tryCatchPattern":null,"preventionTips":["Always set a recognized 'type' on every target.","Lint .gyp files for unknown type values in CI."],"tags":["gyp","msvs","target-type","validation","windows"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}