nodejs/node · error · GypError

Target type %s is not a valid target type for target %s in %

Error message

Target type %s is not a valid target type for target %s in %s.

What it means

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.

Source

Thrown at tools/gyp/pylib/gyp/generator/msvs.py:1147

    Args:
        spec: The target dictionary containing the properties of the target.
        build_file: The path of the gyp file.
    Returns:
        An integer, the configuration type.
    """
    try:
        config_type = {
            "executable": "1",  # .exe
            "shared_library": "2",  # .dll
            "loadable_module": "2",  # .dll
            "static_library": "4",  # .lib
            "windows_driver": "5",  # .sys
            "none": "10",  # Utility type
        }[spec["type"]]
    except KeyError:
        if spec.get("type"):
            raise GypError(
                "Target type %s is not a valid target type for "
                "target %s in %s." % (spec["type"], spec["target_name"], build_file)
            )
        else:
            raise GypError(
                "Missing type field for target %s in %s."
                % (spec["target_name"], build_file)
            )
    return config_type


def _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config):
    """Adds a configuration to the MSVS project.

    Many settings in a vcproj file are specific to a configuration.  This
    function the main part of the vcproj file that's configuration specific.

    Arguments:

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Correct the type to one of: executable, shared_library, loadable_module, static_library, windows_driver, none.
  2. If the type is intentionally non-MSVS, gate that target so it is not built under the msvs generator (use conditions).
  3. Check for typos such as 'shared_lib' vs 'shared_library'.

Example fix

// before
'targets': [{ 'target_name': 'foo', 'type': 'shared_lib' }]
// after
'targets': [{ 'target_name': 'foo', 'type': 'shared_library' }]
Defensive patterns

Strategy: validation

Validate before calling

VALID = {'executable','shared_library','loadable_module','static_library','windows_driver','none'}
if spec.get('type') and spec['type'] not in VALID:
    raise ValueError(f"invalid target type: {spec['type']}")

Type guard

VALID = {'executable','shared_library','loadable_module','static_library','windows_driver','none'}
def is_valid_target_type(spec) -> bool:
    return spec.get('type') in VALID

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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