nodejs/node · error · TypeError

Unknown type {item.__class__.__name__} at index {index}

Error message

Unknown type {item.__class__.__name__} at index {index}

What it means

ProcessVariablesAndConditionsInList handles dict, list, str, and int items; any other item type (bool, float, None, tuple) reaches the final elif and raises this TypeError naming the class and the index. This is the list-context counterpart to error 495 and is raised when the item itself (before any expansion) is an unsupported type.

Source

Thrown at tools/gyp/pylib/gyp/input.py:1432

            if type(expanded) in (str, int):
                the_list[index] = expanded
            elif isinstance(expanded, list):
                the_list[index : index + 1] = expanded
                index += len(expanded)

                # index now identifies the next item to examine.  Continue right now
                # without falling into the index increment below.
                continue
            else:
                raise ValueError(
                    "Variable expansion in this context permits strings and "
                    + "lists only, found "
                    + expanded.__class__.__name__
                    + " at "
                    + index
                )
        elif not isinstance(item, int):
            raise TypeError(
                "Unknown type " + item.__class__.__name__ + " at index " + index
            )
        index = index + 1


def BuildTargetsDict(data):
    """Builds a dict mapping fully-qualified target names to their target dicts.

    |data| is a dict mapping loaded build files by pathname relative to the
    current directory.  Values in |data| are build file contents.  For each
    |data| value with a "targets" key, the value of the "targets" key is taken
    as a list containing target dicts.  Each target's fully-qualified name is
    constructed from the pathname of the build file (|data| key) and its
    "target_name" property.  These fully-qualified names are used as the keys
    in the returned dict.  These keys provide access to the target dicts,
    the dicts in the "targets" lists.
    """

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Replace the offending item with a string or int (use '1'/'0' for booleans, drop None items entirely).
  2. Sanitize the list at the source (the .gypi include or programmatic caller).
  3. Use the index in the message to locate the exact item quickly.

Example fix

// before
'defines': ['FOO', None, 'BAR'],
// after
'defines': ['FOO', 'BAR'],
Defensive patterns

Strategy: type-guard

Validate before calling

for index, item in enumerate(the_list):
    assert isinstance(item, (dict, list, str, int)) and not isinstance(item, bool), \
        f'List item at index {index} has unsupported type {type(item).__name__}'

Type guard

def is_supported_list_item(item) -> bool:
    return isinstance(item, (dict, list, str, int)) and not isinstance(item, bool)

Prevention

When it happens

Trigger: A GYP list literal contains True/False/None/1.5 directly; a programmatic gyp caller appends a non-supported scalar to a list; a .gypi include emits a JSON null or boolean inside a list.

Common situations: Writing 'defines': [None] or 'sources': [True]; templating that drops a value leaving None; JSON merge introducing booleans.

Related errors


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