Skip to content

fix(core): treat extensionless files as JavaScript whose syntax decides its kind - #829

Merged
Brooooooklyn merged 1 commit into
mainfrom
fix/828-extensionless-esm
Oct 12, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
fix/828-extensionless-esm

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Summary

Fixes #828. In a package without "type", an extensionless file containing ES module syntax ran under plain Node.js (syntax detection) but failed under the loader with ERR_REQUIRE_CYCLE_MODULE:

  • create_resolve reports format: "commonjs", so Node skips its own detection.
  • load_commonjs_esm — which flips a CommonJS-reported file with module syntax to module — returned early because SourceType::from_path rejects a path without an extension.
  • The file deferred to the CommonJS loader, which require()d it as an ES module while the ESM loader still held it — the reported cycle.

The new source_type_from_path gives an extensionless path SourceType::unambiguous() — JavaScript whose module kind its syntax decides, exactly what Node does for such a file — and is used in load_commonjs_esm and in oxc_transform's source-type derivation (whose script-to-module retry was skipped for the same reason). TypeScript syntax in an extensionless file still fails to parse: the file type cannot be determined from the name.

Deliberate behavior note

Inside an explicit "type": "commonjs" package the flip now also applies to extensionless files. Plain Node.js is inconsistent there (Node 24 require() executes the file as ESM while Node 26 fails it with SyntaxError), and the loader follows its own existing .js/.ts precedent — files in the same situation already flip, per load_commonjs_esm's documented contract. A regression test pins that semantics.

Test plan

  • New regression tests in cjs-esm-syntax.spec.ts and resolved-format.spec.ts: extensionless ESM-syntax file as entry point and as an import (no-type and type: "commonjs" packages), plus the extensionless CommonJS control.
  • pnpm test, vp check, cargo clippy pass; verified manually on Node 24.21 (module.register()) and 26.11 (registerHooks()): bin/tool prints esm tool directly and when imported, and the CJS-syntax extensionless control still runs as CommonJS.

…es its kind

In a package without "type", create_resolve reports an extensionless file
as commonjs, so Node skips its own syntax detection; load_commonjs_esm —
the piece that flips a CommonJS-reported file with module syntax to an ES
module — then returned early because SourceType::from_path rejects a
path without an extension, and the file deferred to the CommonJS loader,
which require()d it as ESM mid-flight: ERR_REQUIRE_CYCLE_MODULE.

source_type_from_path gives an extensionless path SourceType::unambiguous
— JavaScript whose module kind its syntax decides — used in
load_commonjs_esm and in oxc_transform's source-type derivation, whose
script-to-module retry was skipped for the same reason.

Fixes #828
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T17:21:47.182220Z b02b288 PR opened
ℹ️ 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.

@Brooooooklyn
Brooooooklyn merged commit 4cc5888 into main Oct 12, 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.

Extensionless ES module files fail with ERR_REQUIRE_CYCLE_MODULE in packages without "type"

1 participant