Skip to content

fix(core): run the .js file the entry point or a JavaScript importer names - #881

Merged
Brooooooklyn merged 1 commit into
mainfrom
fix/js-importer-resolves-js
Oct 22, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
fix/js-importer-resolves-js

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Closes #878

Problem

Since #840 every resolve outside node_modules tried TypeScript first. That is right for an import from a TypeScript file, as tsc and tsx resolve it. But it also hit the entry point and imports from JavaScript files, where Node.js and tsx run the .js file that was named.

                         before     after     node   tsx
oxnode ./main.js         main.ts    main.js   main.js main.js
importer.js → ./dep.js   dep.ts     dep.js    dep.js  dep.js
main.ts     → ./dep.js   dep.ts     dep.ts    —       dep.ts   (#840, unchanged)

Fix

There's a new order, ExtensionOrder::Named: the file the specifier names first, then TypeScript. extension_order() picks the order from the importer:

importer in node_modules ──────────────► Package  (unchanged)
importer .ts .tsx .mts .cts .jsx ──────► Source   (unchanged, #840 / #874)
anything else ─────────────────────────► Named    (new)
  entry point · --import preload · .js .mjs .cjs · [eval1] · the importer's directory parent
  • Named aliases: .js → .js .ts .tsx .jsx, .jsx → .jsx .tsx .ts .js, .mjs → .mjs .mts, .cjs → .cjs .cts. A missing .js still finds its .ts, as tsx does.
  • Extensionless ./dep stays TypeScript first, as tsx resolves it.
  • .jsx importers stay TypeScript first: tsx counts .jsx as TypeScript (/\.([cm]?ts|[tj]sx)$/).
  • The node_modules re-resolve now runs for every order but Package. Without that, a .js file importing a package with index.js beside index.ts would get index.ts.
  • require() is unchanged: it already goes to Node's own CommonJS lookup.

Tests

  • Rust: named_order_tries_the_named_file_first and extension_order_follows_the_importer.
  • extension-order.spec.ts:
    • the entry point for .js, .mjs, .cjs, .jsx and extensionless names, with the TypeScript sibling present and with it missing
    • .js, .mjs and .cjs importers
    • a JavaScript importer that finds only TypeScript
    • a .jsx importer
    • a package reached from JavaScript
    • createImporter with a directory parent
  • directory-parent-url.spec.ts: --import ./setup.js with setup.ts beside it.
  • 10 of these fail on main. The rest guard what must not change.
  • vp run test and OXC_TRANSFORM_ALL=true vp run test pass (588), as do cargo test, clippy, lint and fmt.

Not changed

  • tsx goes TypeScript first for JavaScript importers and the entry point when tsconfig has allowJs. oxc-node does not read allowJs for this. Following it would bring this bug back in allowJs projects.
  • require() from TypeScript files still uses Node's lookup (JavaScript first), as before.

🤖 Generated with Claude Code

…names

Since #840, `./x.js` resolved to `x.ts` when both exist, for every
resolve outside node_modules. That matches tsc and tsx for an import from
a TypeScript file, but the entry point and imports from .js, .mjs and
.cjs files ran the TypeScript sibling, where Node.js and tsx run the
named .js file (#878).

A new extension order, `Named`, tries the file a `.js`, `.jsx`, `.mjs`
or `.cjs` specifier names first, then TypeScript. It applies to the
entry point, `--import` preloads and importers that are not TypeScript
or `.jsx` files. Imports from TypeScript keep the #840 order, and a
package reached from JavaScript still runs what it compiled.

Closes #878

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 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-22T05:14:53.950952Z 603529a 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.

@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: 603529af3a

ℹ️ 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
@Brooooooklyn
Brooooooklyn merged commit 761bf54 into main Oct 22, 2026
67 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/js-importer-resolves-js branch October 22, 2026 06:23
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.

An explicit .js entry, and ./x.js imported from JavaScript, run a sibling .ts file

1 participant