Load a module default export from a JS/TS file with robust fallbacks.
Behavior by extension:
.js/.mjs/.cjs: direct dynamic import.
.ts/.mts/.cts/.tsx:
try direct dynamic import (when a TS loader is active),
else compile via esbuild to a cached .mjs file and import (the
module's own code is bundled; Node built-ins and installed ES module
packages stay imports, which Node resolves from the source file),
else fallback to typescript.transpileModule for simple modules.
When every attempt fails, the thrown error's cause is an AggregateError
holding the esbuild and TypeScript failures, in that order.
Compiled builds are cached under .tsbuild/<cacheDirName>/, keeping the
newest GETDOTENV_CACHE_KEEP builds per file name (default 2, minimum 1; a
value that isn't an integer falls back to 2).
Load a module default export from a JS/TS file with robust fallbacks.
Behavior by extension:
.js/.mjs/.cjs: direct dynamic import..ts/.mts/.cts/.tsx:esbuildto a cached.mjsfile and import (the module's own code is bundled; Node built-ins and installed ES module packages stay imports, which Node resolves from the source file),typescript.transpileModulefor simple modules.When every attempt fails, the thrown error's
causeis anAggregateErrorholding the esbuild and TypeScript failures, in that order.Compiled builds are cached under
.tsbuild/<cacheDirName>/, keeping the newestGETDOTENV_CACHE_KEEPbuilds per file name (default 2, minimum 1; a value that isn't an integer falls back to 2).