{"record":{"id":"4ada508b22396c60","repo":"nodejs/node","slug":"could-not-find-pattern-matching-s","errorCode":null,"errorMessage":"Could not find pattern matching %s","messagePattern":"Could not find pattern matching (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"tools/getmoduleversion.py","lineNumber":22,"sourceCode":"\n\ndef get_version():\n  node_version_h = os.path.join(\n    os.path.dirname(__file__),\n    '..',\n    'src',\n    'node_version.h')\n\n  f = open(node_version_h)\n\n  regex = '^#define NODE_MODULE_VERSION [0-9]+'\n\n  for line in f:\n    if re.match(regex, line):\n      major = line.split()[2]\n      return major\n\n  raise Exception('Could not find pattern matching %s' % regex)\n\n\nif __name__ == '__main__':\n  print(get_version())\n","sourceCodeStart":4,"sourceCodeEnd":27,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/getmoduleversion.py#L4-L27","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Run the script from the Node source root so src/node_version.h resolves; verify with: grep NODE_MODULE_VERSION src/node_version.h.","If the header is generated and missing, run configure/generate-sources first to produce it.","If the macro format changed, update the regex in getmoduleversion.py to match the new #define shape."],"exampleFix":"# before (wrong cwd / missing header)\npython tools/getmoduleversion.py\n# after\npython tools/getmoduleversion.py   # run from node source root\ngrep NODE_MODULE_VERSION src/node_version.h   # confirm the macro exists","handlingStrategy":"validation","validationCode":"import os, re\ndef node_version_macro_present(root='.') -> bool:\n    p = os.path.join(root, 'src', 'node_version.h')\n    if not os.path.isfile(p):\n        return False\n    return any(re.match(r'^#define NODE_MODULE_VERSION [0-9]+', line) for line in open(p))","typeGuard":"null","tryCatchPattern":"try:\n    v = get_version()\nexcept Exception as e:\n    if 'Could not find pattern' in str(e):\n        print('Run from the Node source root and ensure src/node_version.h exists / is generated.')\n    raise","preventionTips":["Run getmoduleversion.py from the Node source root.","Ensure configure/generate-sources has produced src/node_version.h.","Update the regex if the NODE_MODULE_VERSION macro format changes."],"tags":["node","versioning","module-version","header","configuration"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}