What this thread does
The problem
An agent changes imports or TypeScript settings and Node startup fails. Match the message to the loading process.
Versions, licences and price scope — checked 2026-10-20
| Tool | Verified scope, not a latest-version claim | Licence / cost |
|---|---|---|
| Node.js | 24.x baseline; native type stripping stable from 24.12.0 per Node TS docs | MIT core plus bundled notices; no core licence fee |
| TypeScript | 6.0 deprecates node10 resolution; 7.0 removes it per release notes | Apache-2.0; no licence fee |
Record node --version and npm ls typescript ts-node tsx mocha. No hosting prices are quoted; commands are untested project recipes.
When to pick which
| Message | Inspect | Repair |
|---|---|---|
| Subpath not exported | First importer and exports condition | Public entry or compatible dependency pair |
| Missing __dirname / require | Extension and nearest package type | ESM equivalent or one CommonJS config |
| Unknown .ts extension | Runner, loader and test glob | Configured TS runner or compiled JS |
| TS5107 | Effective tsconfig including extends | Resolution matching Node or bundler |
ERR_PACKAGE_PATH_NOT_EXPORTED
Exact reported message: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './cid' is not defined by "exports" in /node_modules/multiformats/package.json (first-hand report, checked 2026-10-20).
The active exports mapping does not expose this subpath, possibly because of its condition. Inspect the installed package.json directly. Use npm explain multiformats and npm ls orbit-db multiformats in this example. Replace your import with the public entry; for a dependency-owned import, update its owner to a release with compatible dependencies/exports. Rerun node ./app.mjs, substituting the actual entry.
Do not edit node_modules, bypass exports, delete the lockfile blindly or assume import always repairs this. Node entry points and conditions, checked 2026-10-20, define the rule; no universal multiformats downgrade is established here.
__dirname is not defined in ES module scope
Exact message: ReferenceError: __dirname is not defined in ES module scope, verified independently in TypeScript issue 58658, checked 2026-10-20. ESM does not receive this CommonJS binding. On the baseline above use import.meta.dirname; for older runtimes use a local binding:
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
Rerun node ./app.mjs. Do not substitute process.cwd() unless you want the launch directory, or decode paths using URL.pathname. Node import.meta.dirname, checked 2026-10-20, records stability from 24.0.0 and 22.16.0 and the file-module restriction.
require is not defined in ES module scope
Exact message: ReferenceError: require is not defined in ES module scope, you can use import instead (Gulp report, checked 2026-10-20).
The caller is ESM but uses a CommonJS binding. Prefer static imports. For a genuine CommonJS dependency needing require semantics, define it locally:
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const path = require('node:path');
Rerun node ./app.mjs. For a CommonJS config whose tool supports it, use mv ./tool.config.js ./tool.config.cjs and update references. Do not remove the application's module type to repair one config. createRequire cannot synchronously load an asynchronous ESM graph. Node createRequire, checked 2026-10-20.
ERR_UNKNOWN_FILE_EXTENSION .ts
Verified prefix: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" (Mocha reproduction, checked 2026-10-20). The ESM loader did not recognize the file; installing TypeScript alone does not arrange loading.
For existing ts-node, inspect npm exec -- ts-node --showConfig, then use its documented ESM entry npm exec -- ts-node --esm ./src/main.ts. For a project already using tsx, use node --import=tsx ./src/main.ts. Alternatively run the configured build and its emitted JavaScript entry. Restrict Mocha to test/**/*.test.ts or your own test folder; the scan reached dependency tests. Rerun the failing tests.
Do not blindly mix ts-node/register with unrelated ESM loaders. Native Node stripping ignores tsconfig, excludes TSX and refuses TS under node_modules. ts-node troubleshooting and Node TS support, checked 2026-10-20, explain the options and restrictions.
TS5107 moduleResolution=node10
Exact diagnostic sentence: error TS5107: Option 'moduleResolution=node10' is deprecated and will stop functioning in TypeScript 7.0. Verified in TypeScript Bot's ecosystem run, checked 2026-10-20.
Legacy resolution may be inherited or use the node alias. For direct Node execution pair "module": "nodenext" with "moduleResolution": "nodenext". For bundler-resolved code use its supported settings, typically "module": "preserve" and "moduleResolution": "bundler". Inspect npm exec -- tsc --showConfig, then run npm exec -- tsc --noEmit and the real build/start command. Node ESM may require explicit extensions in relative imports.
Do not choose bundler merely to suppress an error in code Node executes directly. "ignoreDeprecations": "6.0" is temporary suppression, not migration or a runtime fix. TS 6.0 guidance and resolution reference, checked 2026-10-20.
Community evidence and recommendation by constraint
- In nodejs/help 2907, mrddo-com reported the missing directory binding; member lundibundi identified ESM scope, with later users confirming the URL shim.
- Mocha 4952, by patreeceeo, provides a minimal dependency-sensitive test reproduction, not proof of a universal loader fix.
Keep ESM for missing bindings; match resolution to the output loader.
A prompt to give your agent
Read the linked official source for my exact error; do not guess. Record versions, package type, effective tsconfig, first importer and exports condition. Show one repair and rerun the failing command and type-check/build. Preserve unrelated module boundaries.
Mistakes and Limits
No reproductions, builds or upgrades were run. Unverified requested error strings remaining: none. Evidence is historical, not measured October demand. ERR_REQUIRE_ASYNC_MODULE was verified in Firebase 8589 but excluded because node-err-require-esm-require-of-es-module-package already covers it.
Started from a post by @mrddo-com, packaged by the editor. Original post