{
 "action": "Not for automatic application — the patched example does not run on 7.0.2: exit code 1, TypeError: Cannot read properties of undefined (reading 'Node10'). Show this correction to the user as a lead. Replace the old line with the new one; the rest of the code can stay.",
 "alternatives": [
  {
   "action": "Not for automatic application — format removed: there is no replacement to apply. Show this correction to the user as a lead. ts.ModuleKind is not available in typescript 7.0.2; remove or replace this use. The same code works on typescript 6.0.2: pin a version before 7.0.2 if you cannot change the code. Release notes: import express from \"express\";",
   "applicability": {
    "method": "literal_patch",
    "reason": "format removed: there is no replacement to apply",
    "run_on": "7.0.2",
    "status": "not_applicable"
   },
   "by_notes": true,
   "changelog_ref": {
    "quote": "esModuleInterop and allowSyntheticDefaultImports cannot be set to false.",
    "url": "https://github.com/microsoft/TypeScript/releases/tag/v7.0.2"
   },
   "confirmations": 10,
   "detect": [
    "ts.ModuleKind.CommonJS"
   ],
   "equivalence": "not_comparable",
   "format": "removed",
   "kind": "removed",
   "right": "",
   "script_right": "const ts = require(\"typescript\");\n// typescript 7.0.2 only exports `version` and `versionMajorMinor`, so transpileModule,\n// ModuleKind, ScriptTarget and flattenDiagnosticMessageText are unavailable.\n// Node's built-in stripTypeScriptTypes is used instead. It only removes type syntax:\n// the output stays ES module syntax and is not converted to CommonJS or ES2019.\nconst { stripTypeScriptTypes } = require(\"node:module\");\n\nconst source = `import express from \"express\"; const app = express(); app.listen(3000);`;\n\nconst result = {\n  outputText: stripTypeScriptTypes(source, { mode: \"strip\", sourceUrl: \"snippet.ts\" }),\n};\n\nconsole.log(result.outputText);\nprocess.exitCode = 0;",
   "script_wrong": "const ts = require(\"typescript\");\n\nconst source = `import * as express from \"express\"; const app = express(); app.listen(3000);`;\n\nconst result = ts.transpileModule(source, {\n  compilerOptions: {\n    module: ts.ModuleKind.CommonJS,\n    target: ts.ScriptTarget.ES2019,\n    esModuleInterop: false,\n  },\n  fileName: \"snippet.ts\",\n  reportDiagnostics: true,\n});\n\nif (result.diagnostics && result.diagnostics.length > 0) {\n  for (const d of result.diagnostics) {\n    const message = ts.flattenDiagnosticMessageText(d.messageText, \"\\n\");\n    console.error(\"Diagnostic:\", message);\n  }\n}\n\nconsole.log(result.outputText);\nprocess.exitCode = 0;",
   "seen_in_models": [
    "claude-sonnet-5-5",
    "gemini-3.8-flash",
    "gpt-6.1-sol"
   ],
   "wrong": "module: ts.ModuleKind.CommonJS,"
  }
 ],
 "applicability": {
  "exit_code": 1,
  "line": 35,
  "method": "literal_patch",
  "occurrences": 1,
  "patched_sha": "00a3fd63c357",
  "reason": "the patched example does not run on 7.0.2: exit code 1, TypeError: Cannot read properties of undefined (reading 'Node10')",
  "run_on": "7.0.2",
  "status": "fails"
 },
 "by_notes": false,
 "changelog_ref": {
  "quote": "",
  "url": ""
 },
 "confirmations": {
  "failed": 0,
  "worked": 14
 },
 "detect": [
  "ts.ModuleKind.CommonJS"
 ],
 "ecosystem": "npm",
 "equivalence": "same",
 "error_kind": "undefined_prop",
 "error_signature": {
  "message": "Cannot read properties of undefined (reading 'CommonJS')",
  "norm": "undefined_prop:commonjs",
  "type": "TypeError"
 },
 "first_seen": "2026-10-20T16:11:13+00:00",
 "format": "replace",
 "format_version": 2,
 "id": "npm/typescript/7.0.2/0004",
 "kind": "changed",
 "license": "https://creativecommons.org/licenses/by/4.0/",
 "package": "typescript",
 "proof": {
  "applicability": {
   "exit_code": 1,
   "line": 35,
   "method": "literal_patch",
   "occurrences": 1,
   "patched_sha": "00a3fd63c357",
   "reason": "the patched example does not run on 7.0.2: exit code 1, TypeError: Cannot read properties of undefined (reading 'Node10')",
   "run_on": "7.0.2",
   "status": "fails"
  },
  "auto_apply": false,
  "auto_apply_reason": "the patch gives fails when applied word for word",
  "auto_apply_rule": "Automatic application is allowed only when proof.equivalent is true and proof.applicability.status is applies; otherwise show the correction to the user as a lead and do not apply it on your own.",
  "equivalence": "same",
  "equivalent": true,
  "fails_on": "7.0.2",
  "fixed_on": "7.0.2",
  "level": "differential",
  "method": {
   "fix_on": "7.0.2",
   "name": "stdout_match",
   "normalization": "lines stripped, blank lines dropped, runs of whitespace collapsed; memory addresses, timestamps and temporary paths masked",
   "original_on": "6.0.2",
   "scope": "the observable stdout of one example script; return values, files, other inputs and exception types are not compared, so a match is not a proof of equivalent behaviour"
  },
  "script_right": "'use strict';\n\nconst fs = require('node:fs');\nconst path = require('node:path');\nconst ts = require('typescript');\n\nconst projectDir = fs.mkdtempSync('/tmp/ts-module-resolution-');\nconst libraryDir = path.join(projectDir, 'node_modules', 'mylib');\nconst sourceDir = path.join(projectDir, 'src');\n\nfs.mkdirSync(path.join(libraryDir, 'types'), { recursive: true });\nfs.mkdirSync(sourceDir, { recursive: true });\n\nfs.writeFileSync(\n  path.join(libraryDir, 'package.json'),\n  JSON.stringify(\n    { name: 'mylib', version: '1.0.0', types: 'types/index.d.ts' },\n    null,\n    2\n  )\n);\n\nfs.writeFileSync(\n  path.join(libraryDir, 'types', 'index.d.ts'),\n  'export declare const greeting: string;\\n'\n);\n\nconst sourceFile = path.join(sourceDir, 'index.ts');\nfs.writeFileSync(\n  sourceFile,\n  'import { greeting } from \"mylib\";\\nconsole.log(greeting);\\n'\n);\n\n// typescript 7 no longer exposes ModuleKind / ModuleResolutionKind /\n// resolveModuleName in its JS API, so these are plain option strings.\nconst compilerOptions = {\n  module: 'commonjs',\n  moduleResolution: 'nodenext',\n};\n\nfunction isFile(p) {\n  try {\n    return fs.statSync(p).isFile();\n  } catch {\n    return false;\n  }\n}\n\nfunction tryFile(base) {\n  const candidates = [\n    base,\n    base + '.d.ts',\n    base + '.ts',\n    path.join(base, 'index.d.ts'),\n    path.join(base, 'index.ts'),\n  ];\n  return candidates.find(isFile);\n}\n\n// Minimal Node-style lookup of a package's type declarations.\nfunction resolveModuleName(moduleName, containingFile, _options) {\n  let dir = path.dirname(containingFile);\n  for (;;) {\n    const pkgDir = path.join(dir, 'node_modules', moduleName);\n    const pkgJsonPath = path.join(pkgDir, 'package.json');\n    if (isFile(pkgJsonPath)) {\n      const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));\n      for (const entry of [pkg.types, pkg.typings]) {\n        if (typeof entry === 'string') {\n          const found = tryFile(path.join(pkgDir, entry));\n          if (found) return { resolvedModule: { resolvedFileName: found } };\n        }\n      }\n    }\n    const found = tryFile(pkgDir);\n    if (found) return { resolvedModule: { resolvedFileName: found } };\n    const parent = path.dirname(dir);\n    if (parent === dir) break;\n    dir = parent;\n  }\n  return { resolvedModule: undefined };\n}\n\nconst { resolvedModule } = resolveModuleName(\n  'mylib',\n  sourceFile,\n  compilerOptions\n);\n\nif (!resolvedModule) {\n  throw new Error('Failed to resolve mylib');\n}\n\nconsole.log(path.resolve(resolvedModule.resolvedFileName));",
  "script_wrong": "'use strict';\n\nconst fs = require('node:fs');\nconst path = require('node:path');\nconst ts = require('typescript');\n\nconst projectDir = fs.mkdtempSync('/tmp/ts-module-resolution-');\nconst libraryDir = path.join(projectDir, 'node_modules', 'mylib');\nconst sourceDir = path.join(projectDir, 'src');\n\nfs.mkdirSync(path.join(libraryDir, 'types'), { recursive: true });\nfs.mkdirSync(sourceDir, { recursive: true });\n\nfs.writeFileSync(\n  path.join(libraryDir, 'package.json'),\n  JSON.stringify(\n    { name: 'mylib', version: '1.0.0', types: 'types/index.d.ts' },\n    null,\n    2\n  )\n);\n\nfs.writeFileSync(\n  path.join(libraryDir, 'types', 'index.d.ts'),\n  'export declare const greeting: string;\\n'\n);\n\nconst sourceFile = path.join(sourceDir, 'index.ts');\nfs.writeFileSync(\n  sourceFile,\n  'import { greeting } from \"mylib\";\\nconsole.log(greeting);\\n'\n);\n\nconst compilerOptions = {\n  module: ts.ModuleKind.CommonJS,\n  // Node10 (formerly NodeJs) is the traditional Node-style resolver,\n  // distinct from TypeScript's Classic resolver.\n  moduleResolution:\n    ts.ModuleResolutionKind.Node10 ?? ts.ModuleResolutionKind.NodeJs,\n};\n\nconst { resolvedModule } = ts.resolveModuleName(\n  'mylib',\n  sourceFile,\n  compilerOptions,\n  ts.sys\n);\n\nif (!resolvedModule) {\n  throw new Error('Failed to resolve mylib');\n}\n\nconsole.log(path.resolve(resolvedModule.resolvedFileName));",
  "works_on": "6.0.2"
 },
 "right": "module: 'commonjs',",
 "seen_in_models": [
  "gpt-6.1-sol",
  "claude-sonnet-5-5",
  "gemini-3.8-flash"
 ],
 "seq": 4,
 "slug": "moduleresolution-node",
 "source": "pipeline",
 "symbol": "ts.ModuleKind",
 "updated": "2026-10-27T17:19:59+00:00",
 "url": "https://formachines.ai/errata/npm/typescript/0004-moduleresolution-node/",
 "variant_confirmations": 4,
 "variant_models": [
  "gpt-6.1-sol"
 ],
 "verified": "sandbox",
 "versions": {
  "changed_in": ">6.0.2,<=7.0.2",
  "fails_on": "7.0.2",
  "works_on": "6.0.2"
 },
 "wrong": "module: ts.ModuleKind.CommonJS,"
}