Skip to content

feat(core): compile ES module syntax to CommonJS where tsc would (#905) - #911

Merged
Brooooooklyn merged 54 commits into
oxc-project:mainfrom
darcyrush:feat/commonjs-lowering-tsc-parity
Nov 11, 2026
Merged

Brooooooklyn merged 54 commits into
oxc-project:mainfrom
darcyrush:feat/commonjs-lowering-tsc-parity

Conversation

@darcyrush

@darcyrush darcyrush commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

#908 and #910 are merged; this branch is up to date with main.

AI generated, but ran the fix against a full live CJS project. The project uses package.json type as commonjs with all file extensions as .ts running NestJS 12 (ESM) and tests mocked using nodes test module mock.method.

I needed to upgrade to TypeScript 7.0.2 from 5.9.3 which ts-node doesn't support. tsx and other don't support legacy TypeScript decorators (or rather emitDecoratorMetadata, which NestJS uses). I'm not aware of any other JIT that supports CJS projects needing emit decorator metadata on TS7+.

Closes #905

Problem

In a "type": "commonjs" package, a .ts file that uses import/export runs as an ES module under oxc-node, even when tsconfig compiles it to CommonJS. Its namespace object is then frozen, so mock.method() from node:test can't replace its exports. Under tsc it can.

package.json "type": "commonjs", tsconfig "module": "node20"
test.ts: import * as lib from "../src/lib"; mock.method(lib, "compute", …)

                    main                                    this PR   tsc
oxnode --test       TypeError: Cannot redefine property     pass      pass

Node.js' own type stripping doesn't run this file as an ES module either: it rejects it with SyntaxError: Cannot use import statement outside a module.

Fix

A file with ES module syntax is compiled to CommonJS the way tsc compiles it when all of these hold:

  • its package is "type": "commonjs"
  • its tsconfig module is commonjs, node16, node18, node20 or nodenext (any case)
  • its extension is ambiguous: .ts, .tsx, .js, .jsx or none
  • it uses neither import.meta nor top-level await, which have no CommonJS form
  • it declares none of the names the CommonJS wrapper or the helpers below use: exports, require,
    module, __filename, __dirname, __importDefault, __importStar, __exportStar

Anywhere else, such as a package with no "type", "type": "module", or an ES module setting, the file runs as an ES module, as before. Switching a project's "type" to "module" turns the compilation off.

The output has tsc's shape. It's built from the module runner transform's output:

  • An export of a local that is never reassigned is a plain data property (exports.a = void 0; … exports.a = a;). It's writable, so mock.method(namespace, "a") reaches every importer. A hoisted function is exported up front.
  • A reassigned local, a decorated class and a namespace are exports.a itself, as tsc emits them: live, writable, and undefined (not a TDZ error) when an import cycle reads them early. Re-exports stay live through getters, in the form cjs-module-lexer detects, defined after their require(). A reassigned local exported under two names, declared by destructuring or set to an anonymous function also gets a getter.
  • An anonymous default function is hoisted as default_1 and exported up front. A side-effect import is a bare require().
  • A named import is require()'s result. Default and namespace imports go through __importDefault/__importStar, export * through __exportStar, and import() stays import().
  • On the load-hook path the compiled source is returned with format: "commonjs", so an ES module importer gets the named exports.

The compiled code require()s ./lib.js where the source imported ./lib.js. So Module._resolveFilename in register.mjs falls back to the TypeScript source (.js → .ts/.tsx, .jsx → .tsx/.ts, .mjs → .mts, .cjs → .cts). When the output is missing, ./x.js also finds x.jsx and ./x.jsx finds x.js. For a TypeScript importer outside node_modules, it also prefers the source over compiled output sitting beside it, as the ES module resolver does since #840, and config.ts over config.json for ./config; a file inside node_modules keeps its compiled .js. A bare request tries tsconfig paths and baseUrl first, through the new tsconfigPathCandidates binding. The hook thread's helper tag is registered on the main thread too, so the compiled files can require() their helpers.

Under node16, node18 and nodenext, the resolve hook no longer reports every .ts file as an ES module; the package's "type" decides, as it does for tsc. #908 made that change and is merged.

Behaviour changes

These apply only to projects with "type": "commonjs" and one of the module settings above:

  • A file with import/export now runs as CommonJS. An ES module's default import of it is module.exports, with the file's default export at .default, the same as TypeScript types it under nodenext.
  • An ES module importer doesn't see names the file re-exports with export * from another TypeScript file: Node.js only follows re-exports into .js and .cjs files.
  • Under node16/node18/nodenext, a .ts file without module syntax is CommonJS, also when an ES module imports it.
  • An ES module importer's named imports are a snapshot taken when the file finishes loading, as for any CommonJS module.
  • The compiled file's dependencies resolve with the require condition, as under tsc; a package whose exports offers only import fails.
  • Node.js caches a relative require() per directory and request, so when a .js file and a .ts file in one directory both require("./lib.js") next to lib.ts, whichever asks first decides which file both get.
  • require() of an ES module from a compiled file loaded through the module hooks needs esm: populate separate cache for require(esm) in imported CJS nodejs/node#59679 (22.22.3 on the 22.x line). Earlier versions fail with TypeError: Cannot read properties of undefined (reading 'exports').

The README has a new "ES module syntax in a CommonJS package" section covering this.

Tests

  • Rust: commonjs_lowering covers each module setting, the output shape (reassigned exports, side-effect imports, the anonymous default function), the cases that stay ES modules (import.meta, reserved names, esnext, preserve, .mts, a package without "type"), and type-only or declared reserved names that still compile.
  • New packages/integrate-commonjs package ("type": "commonjs", module: nodenext, run with
    oxnode --test), 20 tests:
    • mocking a namespace export, a function and a class, with importers seeing the mock
    • live reassigned exports
    • default, star and CommonJS imports
    • .js names finding .ts, with the source preferred over compiled output beside it
    • an ES module importer's named and default imports
    • import cycles: hoisted functions, and undefined for a reassigned let, a decorated class, a namespace and a re-export read early
    • a namespace import of a CommonJS class keeping its static members
    • a tsconfig paths alias and the .js → .jsx fallback
    • stack trace lines
    • import.meta and top-level await staying ES modules
    • runtime helpers
  • commonjs.test.ts fails to load on main. helpers.test.ts passes on both and guards what must not change.
  • commonjs-lowering.spec.ts (vitest) covers paths and baseUrl, config.ts beside config.json, the .js/.jsx fallbacks, node_modules files and non-enumerable exports.
  • The Clarify module resolution with .ts files using import and package.json type commonjs #905 repro passes on Node.js 26.12.1 and 22.22.1. vp run test (643 vitest tests plus the three node --test packages), cargo test, clippy and fmt pass.

@darcyrush
darcyrush force-pushed the feat/commonjs-lowering-tsc-parity branch from 00d8ed3 to 053adbb Compare November 9, 2026 11:30
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T14:07:18.203743Z 7b0986e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 053adbb0dc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib.rs Resolved
Comment thread packages/core/register.mjs Resolved
Comment thread packages/core/register.mjs Resolved
Comment thread src/lib.rs Resolved
Comment thread packages/core/register.mjs Resolved
@darcyrush

darcyrush commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Further to the LLM responses to the comments above, additional output;

Limitations of the fix

  • Explicitly named tsconfig with references (OXC_TSCONFIG_PATH / TS_NODE_PROJECT): the referenced project that holds the importer is matched by its directory. oxc_resolver matches on its internal paths base (baseUrl, or else the directory), which isn't public. They only differ when a referenced project sets baseUrl outside its own directory.
  • baseUrl after a failed alias: it's also tried when all of an alias's targets are missing, as oxc_resolver does. If the tsconfig's directory is a symlink, the same path can be tried twice before falling back, which only costs a failed lookup.
  • Extensionless rule only for TypeScript/JSX importers: that's the same gate as the existing source-first rule. A .js file with ES module syntax that gets compiled to CommonJS still gets Node.js' order for ./config (.json before .ts), though as an ES module it got TypeScript first. Hand-written CommonJS .js files keep Node.js' behaviour.
  • Directory requests: ./dir with dir/index.json beside dir/index.ts still follows Node.js' order.
  • Behaviour change: every bare, non-built-in require() from a project file now checks tsconfig paths first, so an alias with the same name as an installed package wins for require() too. Each such require() also makes one native call; the tsconfig lookup is cached.
  • Watch mode: the tsconfig reads the new binding makes are reported to the watch parent. The alias targets require() tries are not, whereas the ES module resolver reports the paths it tries. Creating a missing alias target therefore may not trigger a restart. I haven't checked this in practice.
  • Generated loaders: only the new export was added to index.js and index.d.ts. The committed WASI artifacts already lag behind (they lack freezeTsconfig), so I left them for CI to regenerate.

Out of scope / future changes

  • One resolver for require() and import: comments 1, 2, 3 and 5 all came from register.mjs copying the native resolver's rules by hand. Routing require() calls from project files through the native resolver would remove that copy, but it touches conditions, exports maps, symlinks and the hook thread on Node.js < 26.2. It's better as its own PR.
  • Rust unit tests for path_alias_candidates: it's only covered by integration tests for now.

DArcy Rush and others added 2 commits November 9, 2026 14:51
An ES module compiled to CommonJS resolves its imports through
`require()`, so it lost behaviour the ES module resolver gave it:

- try tsconfig `paths` and `baseUrl` before Node.js' own resolution,
  through the new `tsconfigPathCandidates` binding
- prefer `config.ts` over `config.json` for an extensionless request
- keep a package's compiled `.js` when the resolved file is inside
  `node_modules`
- fall back from `./x.js` to `x.jsx`, and from `./x.jsx` to `x.js`,
  without letting either win over a file that exists
- copy non-enumerable exports in `__importStar`, as tsc does

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@darcyrush
darcyrush force-pushed the feat/commonjs-lowering-tsc-parity branch from 977e97f to f4a08d9 Compare November 9, 2026 13:54
Brooooooklyn and others added 2 commits November 10, 2026 19:24
- Reassigned locals, decorated classes and namespaces are `exports.x` itself, as
  tsc emits them: live, writable, and `undefined` rather than a TDZ error when an
  import cycle reads them early. Re-exports are getters defined after their
  `require()`.
- An anonymous default function is hoisted as `default_1` and exported up front.
- A side-effect import is a bare `require()`.
- Only value bindings named like the CommonJS wrapper or the helpers keep a file
  an ES module; types, ambient declarations and type-only imports do not.
- Tests for cycles, a class's statics through a namespace import, `paths` and
  the `.jsx` fallback in a compiled file.
- README: the output's shape, cycles, snapshots for ES importers, the `require`
  condition, the per-directory `require()` cache, and known limits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19c19cd4b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
Comment thread src/lib.rs Resolved
Comment thread src/lib.rs Resolved
…ceiver

- `export const a = 1, b = f();` assigns `exports.a` before `f()` runs, as
  tsc emits it, so an import cycle sees `a`.
- A reassigned export used as a template tag is called as `(0, exports.tag)`,
  as tsc calls it, so it gets no `this`.
- `require(".")` and `require("..")` are relative requests, so a TypeScript
  importer finds `index.ts` before a compiled `index.js` next to it, as for
  `./` and `../`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c135b3d23f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
Comment thread packages/core/register.mjs Resolved
Comment thread packages/core/register.mjs Resolved
…e ES module did

- A package `imports` entry or a self-reference through `exports` that names
  missing compiled output (`#value` -> `./value.js`, only `value.ts` on disk)
  finds its source through the native resolver, with the `require` condition.
- A `.js` file compiled from an ES module resolves an extensionless request
  TypeScript first, as it did as an ES module. It is told apart from
  hand-written CommonJS by `exports.__esModule`, which its first statement sets.
- A source chosen over compiled output goes back through Node.js' resolution,
  so a symlinked source gets its real path and loads once.
- test: the `--kill-timeout=300` watch test no longer expects the app's and
  oxnode's lines in one order, which two processes cannot promise.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4406e93e11

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
Comment thread packages/core/register.mjs Resolved
…fallback

- A package `imports` entry or self-reference that names missing output now
  takes the file Node.js mapped it to, which its error names, so every active
  condition (`--conditions=development`) applies, not a fixed list.
- A relative request Node.js cannot find asks the native resolver, which
  reports its other candidates to watch mode: creating `barrel/index.ts` for
  `import "./barrel"` restarts the app again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a98adf2579

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
Comment thread src/lib.rs Resolved
Comment thread packages/core/register.mjs Resolved
… by the requested name

- `export const [a = 1, b = self.a] = v;` becomes
  `[exports.a = 1, exports.b = self.a] = v;`, as tsc emits it, so each binding
  is exported before the next default runs. Object patterns and rest elements
  too; the pattern's own reads go through `exports`.
- A package `imports` entry or a self-reference that maps to compiled output
  next to its source loads the source, as the ES module resolver did.
- The source is looked for beside the name a request reaches before Node.js
  follows a symlink there: `./alias.js` linking to `build/real.js` finds
  `alias.ts`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f1709b2e4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib.rs Resolved
Comment thread packages/core/register.mjs Resolved
…ry a directory's main source

- The compiled output's prelude and helpers read `Object` and `Symbol`. A file
  that declares either at its top level would hand them its own binding before
  it is initialized, so such a file stays an ES module, as one declaring
  `require` or a helper's name does.
- For `./lib` whose `package.json` `main` names missing output, the source of
  `main` (`src/main.ts` for `./src/main.js`) is tried before the `index.js`
  Node.js falls back to, as the ES module resolver tried it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d218b8eca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
Comment thread packages/core/register.mjs Resolved
…e ES module order

- `./barrel` that Node.js resolves to `barrel/index.json` finds
  `barrel/index.ts` beside it first, as the ES module resolver did.
- An extensionless request takes the ES module resolver's extension order
  before the aliases of the extension Node.js added, so `./dep` beside
  `dep.ts`, `dep.tsx` and `dep.jsx` finds `dep.ts`, not `dep.tsx`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cd3b19f4eb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 771e13fad6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
Comment thread packages/core/register.mjs Resolved
…o a package, and remap bare requests from lowered JavaScript dependencies

- A local file's `./node_modules/pkg` request takes what the ES module
  resolver finds (`index.mjs`) over Node.js' `index.json`. The resolver
  already keeps a package's compiled `lib.js` before its `lib.ts`.
- A `.js` or `.jsx` dependency oxc-node compiles from an ES module
  (`OXC_TRANSFORM_ALL`) resolves a bare request in the package order, as a
  TypeScript one does. A dependency's JavaScript that oxc-node does not
  compile keeps Node.js' answer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52b532f148

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
…cies as an ES module

A `.js` dependency oxc-node compiles from an ES module (`OXC_TRANSFORM_ALL`)
takes the ES module resolver's answer for `./config` too, so `config.ts`
comes before `config.json`, and a compiled `lib.js` still before `lib.ts`.
A dependency's JavaScript that oxc-node does not compile keeps Node.js'
answer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b80428dfdc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
Comment thread packages/core/register.mjs Resolved
…s, and remap from lowered extensionless dependencies

- The conditions forwarded to the ES module resolver include the
  `nodeOptions.conditions` (and `addons`) of the configuration file
  `--experimental-config-file`, `--config-file` or
  `--experimental-default-config-file` names, which Node.js adds to the
  command line's. `#dep` takes the `development` branch Node.js took.
- An extensionless dependency entry oxc-node compiles from an ES module
  (`bin/run`, `OXC_TRANSFORM_ALL`) resolves `../config` as an ES module,
  as a `.js` one does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a26b97fa4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
Node.js adds a configuration file's `nodeOptions.conditions` to those of
the command line, but takes `NODE_OPTIONS`' instead of them. The conditions
forwarded to the ES module resolver now do the same, so `#dep` takes the
branch Node.js took.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24ae4ebd56

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
Comment thread packages/core/register.mjs Resolved
… a configuration file with a byte order mark

- A request the ES module resolver cannot read (`./dep#x.js`) no longer
  takes the source beside a symlink's target: `dep#x.js` linking to
  `build/real.js` keeps it, as Node.js found it, when no `dep#x.ts`
  stands beside the requested name.
- The configuration file whose conditions are forwarded may start with a
  byte order mark, as Node.js accepts it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60b755a77f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
Comment thread src/lib.rs Resolved
Comment thread packages/core/register.mjs Resolved
…onditions, and keep an exact extensionless link

- The `exports.a = exports.b = … = void 0` prelude is split into chains
  of 50, as `tsc` emits it: one chain of thousands of exports nested too
  deep for V8 to compile.
- The ES module resolver maps a request with the conditions Node.js hands
  `_resolveFilename` as `options.conditions`, which a
  `module.registerHooks()` hook may have changed, and with the startup ones
  otherwise.
- An extensionless request whose exact name is a symlink (`./bin#x`) keeps
  the file it links to, as Node.js takes the exact file first, when no
  source stands beside that name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 07fb88136d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
Comment thread packages/core/register.mjs Resolved
Comment thread packages/core/register.mjs Resolved
…does, and `--no_addons`

Checked against Node.js 22.23, 24.15, 24.21, 26.0 and 26.13:

- `NODE_OPTIONS`, set at all, even empty, keeps Node.js from taking a
  configuration file's options, so its conditions are not forwarded then.
- Given `--experimental-config-file` and `--experimental-default-config-file`
  both, Node.js 24.19 and 26.1 and later take the flag that comes last,
  earlier versions the named file; the forwarded conditions follow.
- `--no_addons` is `--no-addons`, as Node.js reads `_` in an option's name.
- A configuration file's `addons` is no longer read: Node.js 22 ignores it,
  and where Node.js takes it, the native binding cannot load.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 303f39ebd0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
…ddons` condition

`node-addons` is forwarded unless `process.dlopen()` reports
`ERR_DLOPEN_DISABLED`, which Node.js throws before it looks for the file
whenever addons are off: by `--no-addons`, `--no_addons`, or a
configuration file's `addons` where the running version reads it (Node.js
22 does not, 24 and 26 do, and not with `NODE_OPTIONS` set). This replaces
parsing those flags.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc5e84ae1b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
…file sets NODE_OPTIONS

Node.js drops a configuration file's options when the process starts with
`NODE_OPTIONS`, not when an `--env-file` sets it: it reads that file later,
and keeps a variable the environment already has. `NODE_OPTIONS` that holds
what an `--env-file` or `--env-file-if-exists` of the command line sets
counts as unset for this, checked on Node.js 22.23, 24.15, 24.21 and 26.13.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7b0986e43a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/register.mjs Resolved
@Brooooooklyn
Brooooooklyn merged commit 6f1f435 into oxc-project:main Nov 11, 2026
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify module resolution with .ts files using import and package.json type commonjs

2 participants