Skip to content

fix(core): resolve a .jsx specifier to its .tsx or .ts source - #874

Merged
Brooooooklyn merged 2 commits into
oxc-project:mainfrom
RaphaelFakhri:fix/jsx-specifier-resolves-tsx
Oct 22, 2026
Merged

Brooooooklyn merged 2 commits into
oxc-project:mainfrom
RaphaelFakhri:fix/jsx-specifier-resolves-tsx

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

Summary

Outside node_modules, import "./App.jsx" fails with ERR_MODULE_NOT_FOUND when only App.tsx exists. tsc and tsx resolve a .jsx specifier to .tsx, then .ts, then .jsx, then .js.

This change adds that .jsx extension alias to the source-first resolver options, next to the existing .js, .mjs and .cjs aliases. Files inside node_modules keep the package order and are unchanged.

As with ./dep.js after #851, ./dep.jsx now picks dep.tsx when both files exist. The resolved-format test that kept dep.tsx and dep.jsx side by side now uses other.jsx for its .jsx probe, so it still checks the module format of a .jsx file.

Test plan

  • New integration test in extension-order.spec.ts: ./dep.jsx picks dep.tsx over dep.jsx, and ./util.jsx finds util.ts. It fails on main with ERR_MODULE_NOT_FOUND and passes with this change.
  • source_order_tries_typescript_first asserts the new alias.
  • pnpm test: 550 passed, 19 skipped. cargo test, cargo clippy --all-targets --all-features -- -D warnings, cargo fmt --check and vp lint pass.

Fixes #873

RaphaelFakhri and others added 2 commits October 21, 2026 07:34
Outside node_modules, `./x.jsx` now tries `x.tsx`, `x.ts`, `x.jsx` and
`x.js`, as tsc and tsx resolve it. Before, `import './App.jsx'` with only
`App.tsx` on disk failed with ERR_MODULE_NOT_FOUND.
…ack comment

The node_modules fallback comment said the two orders only disagree on a
source-first extension. A project's .jsx import into a package can now
land on its .js, which the package order would not find; tsc and tsx
resolve it the same way, so the result is kept and the comment says so.

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

Copy link
Copy Markdown
Member

@codex review

@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-22T03:24:51.087096Z fce38a2 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: fce38a26a9

ℹ️ 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".

@Brooooooklyn
Brooooooklyn merged commit db73feb into oxc-project:main Oct 22, 2026
67 checks passed
Brooooooklyn added a commit that referenced this pull request Oct 22, 2026
…names (#881)

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](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

./x.jsx does not resolve to x.tsx or x.ts

2 participants