v2.0.0
π Highlights
π₯ Native ESM
jiti v2 now natively supports ESM import and resolution with new API await jiti.import(id)
and jiti.esmResolve(id)
. This allows top-level await
and native+faster importing of ES-only modules with increased compatibility
βοΈ JSX Support
You can now directly import .jsx
/.tsx
files with jiti! See examples with nano-js, preact, React and Vue. This feature is opt-in for now (using jsx: true
or JITI_JSX=true
). Jiti is considering a smarter lib detection for wider support before enabling JSX support by default.
π¦ Dual format package exports
jiti
package exports are now in a dual (ESM/CJS) format for better importing of jiti in ESM contexts.
π jiti/native
As native ESM and Typescript support is being increased across runtimes, a new export in jiti allows easing up the transition by giving the same API of jiti but instead only depending on runtime import.meta.resolve
and dynamic import()
support. This is possible by making an alias for jiti
to jiti/native
.
π ESM Loader
You can globally register jiti using Node.js global hooks (experimental).
CLI:
# Instead of `npx jiti index.ts`
node --import jiti/register index.ts
Programmatic:
import "jiti/register";
// or
await import("jiti/register");
π Better inspection
You can inspect what jiti internals using debug
option or JITI_DEBUG=1
environment variable. The output is now more readable and with colors to easily find slow imports.
jiti will also use node_modules/.cache/jiti
directory instead of temp dir (if node_modules
exists) to store caches for easier local inspections.
β¬οΈ Migration
Upgrade jiti
dependency to ^2.0.0
in package.json
Use new createJiti
named export :
ESM:
--- import createJiti from "jiti"
+++ import { createJiti } from "jiti"
const jiti = createJiti(import.meta.url)
CommonJS:
--- const createJiti = require("jiti")
+++ const { createJiti } = require("jiti")
const jiti = createJiti(__filename)
Migrate from CommonJS to ESM API: (highly recommended!)
Importing modules:
--- const mood = jiti('mod')
+++ const mood = await jiti.import('mod')
Resolving modules:
--- const path = jiti.resolve('mod')
+++ const path = jiti.esmResolve('mod')
β€οΈ Thank you!
This release wasn't possible without valuable ecosystem feedback and contributors. With the trust of users with astonishing 60M+ monthly downloads, i hope jiti v2 can help speed up the ecosystem transition to ESM and Typescript.
Changes since v1
π Enhancements
- top-level
await
support (#239) - Native ESM support (#259)
- Add experimental ESM loader support (#266)
- Allow try and other resolve options for
jiti.esmResolve
(#268) - Allow configure
interopDefault
usingJITI_INTEROP_DEFAULT
env (1c080a1) jiti/native
subpath (#289) (#294) (#293)- Handle
data:
imports (#299) - Support opt-in JSX (#200)
- Eval ESM modules with fallback loader (#300)
- Support
import.meta.resolve
(#301)
π¦ Build
π₯ Performance
π©Ή Fixes
- Use distinct cache paths for async mode (6e8ec7a)
- Resolve with ESM conditions in async context (#264)
- cache: Prefer
node_modules/.cache
if exists (832f206) - Use native ESM import for built-ins (54d6b4a)
- Respect
interopDefault
in babel transform (485b4e9) - Split cache based on
interopDefault
(f820a15) - Remove extention from cache path (50b1b3a)
- Properly resolve
.mts
/.cts
with.mjs
/.cjs
imports (a5aefad) - resolve: Make sure
parentURL
is a dir (d224e84) - Handle global
URL
instance mismatch (#298) - Optional access to
Reflect.metadata
for typescript decorators (#165) - Only pass
paths
option to nativerequire.resolve
(50e4280)
π Refactors
- Split option normalization (#172)
- Split logic (#240)
- Remove legacy Node.js syntax polyfills (#260)
- 3rd arg to
createJiti
is optional (60a23e3) - Upgrade cache version to 8 (99224ae)
- Use more clear
fsCache
andmoduleCache
options (#263) - Use ESM imports for babel plugins (22e259f)
- Improve debug logging (463a8a3)
- Rename
importResolve
toesmResolve
(aac88e6) - Improve env handling (ee4489d)
- Use
import
/require
in debug logs (934a5bb) - Improve internal babel types (#271)
- Rename
experimentalBun
option totryNative
(#295) - Make
jiti.esmResolve
consistent withimport.meta.resolve
(#303)