Repository navigation
fix(core): treat extensionless files as JavaScript whose syntax decides its kind - #829
Merged
Merged
Conversation
…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
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withERR_REQUIRE_CYCLE_MODULE:create_resolvereportsformat: "commonjs", so Node skips its own detection.load_commonjs_esm— which flips a CommonJS-reported file with module syntax tomodule— returned early becauseSourceType::from_pathrejects a path without an extension.require()d it as an ES module while the ESM loader still held it — the reported cycle.The new
source_type_from_pathgives an extensionless pathSourceType::unambiguous()— JavaScript whose module kind its syntax decides, exactly what Node does for such a file — and is used inload_commonjs_esmand inoxc_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 24require()executes the file as ESM while Node 26 fails it withSyntaxError), and the loader follows its own existing.js/.tsprecedent — files in the same situation already flip, perload_commonjs_esm's documented contract. A regression test pins that semantics.Test plan
cjs-esm-syntax.spec.tsandresolved-format.spec.ts: extensionless ESM-syntax file as entry point and as an import (no-typeandtype: "commonjs"packages), plus the extensionless CommonJS control.pnpm test,vp check,cargo clippypass; verified manually on Node 24.21 (module.register()) and 26.11 (registerHooks()):bin/toolprintsesm tooldirectly and when imported, and the CJS-syntax extensionless control still runs as CommonJS.