nodejs/node · error · Exception

Could not find pattern matching %s

Error message

Could not find pattern matching %s

What it means

Raised by get_version() in Node's tools/getmoduleversion.py after scanning src/node_version.h line by line for the regex '^#define NODE_MODULE_VERSION [0-9]+' and finding no match. The script exists solely to extract the ABI module version integer from that header.

Source

Thrown at tools/getmoduleversion.py:22


def get_version():
  node_version_h = os.path.join(
    os.path.dirname(__file__),
    '..',
    'src',
    'node_version.h')

  f = open(node_version_h)

  regex = '^#define NODE_MODULE_VERSION [0-9]+'

  for line in f:
    if re.match(regex, line):
      major = line.split()[2]
      return major

  raise Exception('Could not find pattern matching %s' % regex)


if __name__ == '__main__':
  print(get_version())

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Run the script from the Node source root so src/node_version.h resolves; verify with: grep NODE_MODULE_VERSION src/node_version.h.
  2. If the header is generated and missing, run configure/generate-sources first to produce it.
  3. If the macro format changed, update the regex in getmoduleversion.py to match the new #define shape.

Example fix

# before (wrong cwd / missing header)
python tools/getmoduleversion.py
# after
python tools/getmoduleversion.py   # run from node source root
grep NODE_MODULE_VERSION src/node_version.h   # confirm the macro exists
Defensive patterns

Strategy: validation

Validate before calling

import os, re
def node_version_macro_present(root='.') -> bool:
    p = os.path.join(root, 'src', 'node_version.h')
    if not os.path.isfile(p):
        return False
    return any(re.match(r'^#define NODE_MODULE_VERSION [0-9]+', line) for line in open(p))

Type guard

null

Try / catch

try:
    v = get_version()
except Exception as e:
    if 'Could not find pattern' in str(e):
        print('Run from the Node source root and ensure src/node_version.h exists / is generated.')
    raise

Prevention

When it happens

Trigger: Running getmoduleversion.py when src/node_version.h does not contain a NODE_MODULE_VERSION #define matching the expected pattern — e.g. the header is missing, regenerated differently, or the macro format changed.

Common situations: Running the script from a directory where src/node_version.h is absent (wrong cwd, partial checkout); a Node version where the macro was renamed or reformatted; a generated header that wasn't produced yet (clean checkout before configure).

Related errors


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