nodejs/node · error · Exception
Could not find pattern matching %s
Error message
Could not find pattern matching %s
What it means
Raised by get_napi_version() in tools/getnapibuildversion.py after it opens ../src/node_version.h (relative to the script) and iterates every line without finding one matching '^#define NODE_API_SUPPORTED_VERSION_MAX'. The file was readable, but the expected N-API version macro is absent. This script feeds Node's native-addon build system the maximum stable N-API version, so a missing macro means the build cannot pick an N-API target.
Source
Thrown at tools/getnapibuildversion.py:22
def get_napi_version():
napi_version_h = os.path.join(
os.path.dirname(__file__),
'..',
'src',
'node_version.h')
f = open(napi_version_h)
regex = '^#define NODE_API_SUPPORTED_VERSION_MAX'
for line in f:
if re.match(regex, line):
napi_version = line.split()[2]
return napi_version
raise Exception('Could not find pattern matching %s' % regex)
if __name__ == '__main__':
print(get_napi_version())
View on GitHub (pinned to 1b2de5e052)
Solutions
- Open src/node_version.h and confirm a line exactly like '#define NODE_API_SUPPORTED_VERSION_VERSION_MAX 9' exists; if missing, update the Node checkout.
- Ensure the script is run from the correct repo root so '../src/node_version.h' resolves to the real Node header (check `os.path.dirname(__file__)/../src/node_version.h`).
- If you maintain a fork that renamed the macro, patch the regex at getnapibuildversion.py:15 to match the new name.
- Pin to a Node version known to ship the macro rather than a stripped/custom header.
Example fix
// before
regex = '^#define NODE_API_SUPPORTED_VERSION_MAX'
// after (also accept a legacy/renamed macro, fail loudly with file context)
regex = r'^#\s*define\s+NODE_API_SUPPORTED_VERSION_MAX\b'
if not os.path.exists(napi_version_h):
raise Exception('node_version.h not found at %s' % napi_version_h) Defensive patterns
Strategy: validation
Validate before calling
import os, re
h = os.path.join(os.path.dirname(__file__), 'src', 'node_version.h')
if not os.path.exists(h):
raise SystemExit('node_version.h missing at %s' % h)
found = any(re.match(r'^#define\s+NODE_API_SUPPORTED_VERSION_MAX\b', line)
for line in open(h))
if not found:
raise SystemExit('macro not present; update Node checkout') Type guard
def has_napi_macro(header_path: str) -> bool:
import re
if not os.path.isfile(header_path):
return False
pat = re.compile(r'^#define\s+NODE_API_SUPPORTED_VERSION_MAX\b')
return any(pat.match(line) for line in open(header_path)) Try / catch
try:
napi = get_napi_version()
except Exception as e:
# header present but macro absent -> wrong/old Node source
raise SystemExit('Cannot determine N-API version: %s. Check src/node_version.h.' % e) Prevention
- Pin the Node source checkout to a version known to ship NODE_API_SUPPORTED_VERSION_MAX (>= 8.6.0).
- Run getnapibuildversion.py from the repo root so the relative ../src path resolves correctly.
- In CI, assert the macro exists before invoking the native build step.
When it happens
Trigger: Calling `python tools/getnapibuildversion.py` (or having node-gyp/gyp invoke it during a native module build) when the checked-out src/node_version.h predates N-API, has been stripped, or the script is run from a tree where src/ is not the matching Node source. The regex matches only a literal '#define NODE_API_SUPPORTED_VERSION_MAX' line; any reformatting (e.g. extra spaces, renamed macro) also misses.
Common situations: Building against an old Node checkout (pre-8.6.0) that never had the macro; running the tool standalone outside a Node source tree; vendoring only part of Node's src/; a downstream fork that renamed the macro.
Related errors
- --enable-v8windbg is incompatible with --without-bundled-v8.
- --v8-enable-hugepage is supported only on linux.
- Only one of the --v8-enable-object-print or --v8-disable-obj
- Only one of the --v8-enable-temporal-support or --v8-disable
- Unexpected error while reading %s: %s
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/05ad4c5f12527dd5.
Report an issue: GitHub.