Back to Tsx

Module resolution

notes/esbuild/module-resolution.md

4.23.91.2 KB
Original Source

Module resolution

esbuild tries an explicit path before extension candidates: ./value.js resolves an existing value.js before TypeScript substitution, and falls back to value.ts only when the requested file is absent (resolver).

Implicit resolution is TypeScript-first locally and JavaScript-first inside node_modules (regression test); the dependency order avoids executing TypeScript source that a published package did not intend as runtime code (0.18.0 rationale).

Known JavaScript output extensions use substitution, while resolveExtensions supplies appended candidates: an existing asset.json wins over asset.json.js, but a missing explicit asset can reach appended extensions (loadAsFile).