Skip to content

Commit 1dfad37

Browse files
docs: cite esbuild's extension-resolution model in node notes
1 parent 257bbbb commit 1dfad37

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

notes/node/cjs-loader.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ tsx resolves TypeScript extensions by trying candidates and catching expected mi
6060
- `.js`/`.jsx`/`.cjs`/`.mjs` swap candidates do not get extra appended-extension guesses;
6161
- cheap existence checks skip missing file candidates before invoking Node's expensive failed-resolution path.
6262

63+
This matches the model documented by esbuild (prior art): it separates "TypeScript's file extension swapping" (`.js``.ts`, only for known JS extensions) from Node's implicit file extension searching (appending to an extension-less path). Neither appends onto an existing extension, so neither resolves `x.js.ts` from `./x.js` ([evanw/esbuild#3201](https://github.com/evanw/esbuild/issues/3201)).
64+
6365
Rejected alternative: detecting the `resolveAsCommonJS` call frame and skipping work only during error decoration. That would depend on an internal frame name and only treat one symptom. Candidate hygiene reduces the miss count and cost everywhere. The behavior is protected by resolution-priority tests in `tests/specs/resolution-priority.ts`.
6466

6567
## Implementation history in tsx

0 commit comments

Comments
 (0)