nodejs/node · error · GypError
Target %s has an invalid target type '%s'. Must be one of %
Error message
Target %s has an invalid target type '%s'. Must be one of %s.
What it means
ValidateTargetType restricts 'type' to a fixed set VALID_TARGET_TYPES: executable, loadable_module, static_library, shared_library, mac_kernel_extension, none, windows_driver. A type outside this set (or missing, since .get returns None) raises GypError listing the allowed values joined by '/'.
Source
Thrown at tools/gyp/pylib/gyp/input.py:2691
Arguments:
target: string, name of target.
target_dict: dict, target spec.
Raises an exception on error.
"""
VALID_TARGET_TYPES = (
"executable",
"loadable_module",
"static_library",
"shared_library",
"mac_kernel_extension",
"none",
"windows_driver",
)
target_type = target_dict.get("type", None)
if target_type not in VALID_TARGET_TYPES:
raise GypError(
"Target %s has an invalid target type '%s'. "
"Must be one of %s." % (target, target_type, "/".join(VALID_TARGET_TYPES))
)
if (
target_dict.get("standalone_static_library", 0)
and not target_type == "static_library"
):
raise GypError(
"Target %s has type %s but standalone_static_library flag is"
" only valid for static_library type." % (target, target_type)
)
def ValidateRulesInTarget(target, target_dict, extra_sources_for_rules):
"""Ensures that the rules sections in target_dict are valid and consistent,
and determines which sources they apply to.
Arguments:View on GitHub (pinned to 1b2de5e052)
Solutions
- Set 'type' to one of: executable, static_library, shared_library, loadable_module, mac_kernel_extension, none, windows_driver.
- Fix typos in the type string.
- If the type was omitted, add it explicitly.
- Confirm the type is supported by the generator in use.
Example fix
// before: { 'target_name':'foo', 'type':'static_lib' }
// after: { 'target_name':'foo', 'type':'static_library' } Defensive patterns
Strategy: validation
Validate before calling
VALID = ('executable','loadable_module','static_library','shared_library','mac_kernel_extension','none','windows_driver')
for t, spec in targets.items():
assert spec.get('type') in VALID, 'invalid type for %s' % t
Type guard
def valid_target_type(spec): return spec.get('type') in ('executable','loadable_module','static_library','shared_library','mac_kernel_extension','none','windows_driver') Try / catch
try:
gyp.main(args)
except gyp.input.GypError as e:
if 'invalid target type' in str(e): print('Set type to one of the VALID_TARGET_TYPES'); raise Prevention
- Always set a valid type string.
- Reuse a target template with the correct type.
- Lint types in pre-commit.
When it happens
Trigger: target_dict['type'] (via .get defaulting None) is not one of the seven valid strings. Reached during target validation in the load pipeline.
Common situations: Typo like 'static_libary' or 'shared_lib'; using a non-portable type; omitting 'type' entirely; using a generator-specific type the core does not recognize; stale type from an old gyp version.
Related errors
- Missing 'target_name' field in target.
- Missing 'type' field in target %s
- Target %s has type %s but standalone_static_library flag is
- Found wildcard in {dependency_key} of {target} referring to
- Dependency '%s' not found while trying to load target %s
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/cfd3624528b85f99.
Report an issue: GitHub.