Repository navigation
fix(core): resolve TypeScript before JavaScript outside node_modules - #851
Merged
Merged
Conversation
With `dep.js` beside `dep.ts`, `./dep.js` and `./dep` resolved to `dep.js`, so a project that compiles in place ran stale output, and `./x.js` never reached `x.jsx`. Importers outside `node_modules` now use a resolver that tries `.ts`/`.tsx` before `.js` (and `.mts`/`.cts` before `.mjs`/`.cjs`), and maps `.js` to `.jsx` too, as tsc and tsx do. Importers inside `node_modules` keep the JavaScript-first order, and a TypeScript file the source order finds inside `node_modules` is re-resolved with it, so packages keep running what they compiled. Closes #840 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c9a18b9a55
ℹ️ 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".
The source order tries `.jsx` ahead of `.mjs`/`.cjs`, so a package whose extensionless entry has `index.jsx` beside a compiled `index.mjs` loaded the `.jsx`, which Node rejects inside node_modules. Re-resolve with the package order for every extension the source order tries early: `.ts`, `.tsx`, `.mts`, `.cts` and `.jsx`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Brooooooklyn
added a commit
that referenced
this pull request
Oct 22, 2026
## 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 --------- Co-authored-by: LongYinan <lynweklm@gmail.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Closes #840
Problem
The resolver put
.jsfirst in the.jsextension alias ([".js", ".ts", ".tsx"]), and before.tsinextensions. Withdep.jsbesidedep.ts, both./dep.jsand./depresolved todep.js. tsc and tsx resolve both todep.ts, so a project that compiles in place, or keeps generated.jsbeside its sources, ran stale output. The alias also had no.jsx, soimport './dep.js'failed when onlydep.jsxexisted.Fix
Two orders.
resolver_for_conditionsnow caches resolvers by export conditions and anExtensionOrder:Source, for the entry point and importers outsidenode_modules:.js → .ts, .tsx, .js, .jsx,.mjs → .mts, .mjs,.cjs → .cts, .cjs.ts, .tsx, .js, .jsx, .mts, .mjs, .cts, .cjs, .json, .wasm, .nodePackage, for importers insidenode_modules: the existing JavaScript-first options, unchanged.Packages keep their compiled output. A bare import from project code resolves with the
Sourceorder. That would pick a package's.tssources when the package ships them beside its compiled.js. So when theSourceorder lands on a TypeScript file insidenode_modules, the request is resolved again with thePackageorder. This retry only happens when a TypeScript file insidenode_modulesis picked, so it's rare.Tests
Rust unit test for the
Sourceorder.packages/integrate-vitest/__tests__/extension-order.spec.ts:dep.tswins overdep.jsfor both./dep.jsand./dep(the issue's example).mts/.ctswin over.mjs/.cjs./dep.jsand./depfinddep.jsxdep.jsstill resolves.tsbeside.jsstill runs its.js, both from the project's bare import and from its own relative importsThe first three fail on
main.Verification (macOS arm64, Node 24.22)
cargo test --all-features,cargo clippy --all-targets --all-features -- -D warnings,vp run test(215 passed) andvp run lintall pass.Not covered
CommonJS
require('./dep')from a.ctsfile goes through Node's own CommonJS resolver, not this one, and still picksdep.js; tsx picksdep.ts. Fixing that means hooking CommonJS filename resolution inregister.mjs, so it is left for a follow-up.🤖 Generated with Claude Code