formachines / errata

Errata / npm / typescript

ts.ModuleKind changed in typescript 7.0.2

In our sandbox runs up to 2026-10-27, gpt-6.1-sol, claude-sonnet-5-5 and gemini-3.8-flash wrote module: ts.ModuleKind.CommonJS, for typescript. It fails on 7.0.2 with TypeError (changed between 6.0.2 and 7.0.2). Use module: 'commonjs', instead.

What to do
replace the line
Output
same on one example
Patch
fails when applied word for word
Auto-apply
not allowed
Seen in
3 models
Worked / failed
14 / 0
Last verified
2026-10-27

What to do

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.

Automatic application: not allowed — the patch gives fails when applied word for word. 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. The change itself is described by kind (changed); the checks are in proof; neither follows from the other.

How to tell this applies to your code

Old and new code

module: ts.ModuleKind.CommonJS,
module: 'commonjs',

Error on 7.0.2:

TypeError: Cannot read properties of undefined (reading 'CommonJS')

Other verified fixes

The fix above passed 4 times. These also passed in the sandbox for the same error; pick the one that matches what your code needs.

No direct replacement · passed 10 times · claude-sonnet-5-5, gemini-3.8-flash, gpt-6.1-sol · patch: nothing to apply word for word

module: ts.ModuleKind.CommonJS,

No direct replacement: drop this use.

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";

Alternatives are leads for the user, not for automatic application: 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.

Sandbox proof
Scripttypescript versionResult
Code the models wrote6.0.2works
Code the models wrote7.0.2fails: TypeError
Verified example below7.0.2works
Output of the verified example7.0.2same as the original's on 6.0.2 (observed stdout of one example; not a proof of equivalent behaviour)
Patch applied word for word to the example7.0.2applied word for word, the patch does not give the verified example's result — the patched example does not run on 7.0.2: exit code 1, TypeError: Cannot read properties of undefined (reading 'Node10')

Verified example for typescript 7.0.2

'use strict';

const fs = require('node:fs');
const path = require('node:path');
const ts = require('typescript');

const projectDir = fs.mkdtempSync('/tmp/ts-module-resolution-');
const libraryDir = path.join(projectDir, 'node_modules', 'mylib');
const sourceDir = path.join(projectDir, 'src');

fs.mkdirSync(path.join(libraryDir, 'types'), { recursive: true });
fs.mkdirSync(sourceDir, { recursive: true });

fs.writeFileSync(
  path.join(libraryDir, 'package.json'),
  JSON.stringify(
    { name: 'mylib', version: '1.0.0', types: 'types/index.d.ts' },
    null,
    2
  )
);

fs.writeFileSync(
  path.join(libraryDir, 'types', 'index.d.ts'),
  'export declare const greeting: string;\n'
);

const sourceFile = path.join(sourceDir, 'index.ts');
fs.writeFileSync(
  sourceFile,
  'import { greeting } from "mylib";\nconsole.log(greeting);\n'
);

// typescript 7 no longer exposes ModuleKind / ModuleResolutionKind /
// resolveModuleName in its JS API, so these are plain option strings.
const compilerOptions = {
  module: 'commonjs',
  moduleResolution: 'nodenext',
};

function isFile(p) {
  try {
    return fs.statSync(p).isFile();
  } catch {
    return false;
  }
}

function tryFile(base) {
  const candidates = [
    base,
    base + '.d.ts',
    base + '.ts',
    path.join(base, 'index.d.ts'),
    path.join(base, 'index.ts'),
  ];
  return candidates.find(isFile);
}

// Minimal Node-style lookup of a package's type declarations.
function resolveModuleName(moduleName, containingFile, _options) {
  let dir = path.dirname(containingFile);
  for (;;) {
    const pkgDir = path.join(dir, 'node_modules', moduleName);
    const pkgJsonPath = path.join(pkgDir, 'package.json');
    if (isFile(pkgJsonPath)) {
      const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
      for (const entry of [pkg.types, pkg.typings]) {
        if (typeof entry === 'string') {
          const found = tryFile(path.join(pkgDir, entry));
          if (found) return { resolvedModule: { resolvedFileName: found } };
        }
      }
    }
    const found = tryFile(pkgDir);
    if (found) return { resolvedModule: { resolvedFileName: found } };
    const parent = path.dirname(dir);
    if (parent === dir) break;
    dir = parent;
  }
  return { resolvedModule: undefined };
}

const { resolvedModule } = resolveModuleName(
  'mylib',
  sourceFile,
  compilerOptions
);

if (!resolvedModule) {
  throw new Error('Failed to resolve mylib');
}

console.log(path.resolve(resolvedModule.resolvedFileName));

Source

No release-note sentence matched this change; the evidence is the sandbox check above.

Seen in: gpt-6.1-sol, claude-sonnet-5-5, gemini-3.8-flash · First seen 2026-10-20 · Last verified 2026-10-27 · All corrections for typescript

For agents