Packages

jiti

2.7.0 · 5 May 2026MIT267.2M / weekRepositoryHomepagenpmAtom feed

Your version

2.0.0

major25 Sep 2024Where it was published

2.7.0 is the newest release of 2.x.

Summary· from the note as AI read it

Migration neededRead before upgrading: 7 changes to make.

Before you upgrade

  • Switch to the createJiti named export instead of the default export
  • Check how jiti is imported; package exports changed
  • Ensure a modern Node.js version; legacy syntax polyfills are goneTo check
  • Rename cache options to fsCache and moduleCache
  • Rename importResolve calls to esmResolve
  • Rename the experimentalBun option to tryNative
  • Check esmResolve results; now behaves like import.meta.resolve

New

  • 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 de
  • Dual format package exports

In short

7 breaking23 new2 faster14 fixed10 internal

  • Breaking

    Use new createJiti named export :

  • Breaking

    Overhaul package exports

  • Breaking

    Remove legacy Node.js syntax polyfills

    To check
  • Breaking

    Use more clear fsCache and moduleCache options

  • Breaking

    Rename importResolve to esmResolve

  • Breaking

    Rename experimentalBun option to tryNative

  • Breaking

    Make jiti.esmResolve consistent with import.meta.resolve

Release note

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')

Changes since v1

compare changes

Enhancements

  • top-level await support

  • Native ESM support

  • Add experimental ESM loader support

  • Allow try and other resolve options for jiti.esmResolve

  • Allow configure interopDefault using JITI_INTEROP_DEFAULT env

  • jiti/native subpath

  • Handle data: imports

  • Support opt-in JSX

  • Eval ESM modules with fallback loader

  • Support import.meta.resolve

Performance

  • Reduce overhead of jiti sub-instances

  • Use native createRequire

Fixes

  • Use distinct cache paths for async mode

  • Resolve with ESM conditions in async context

  • cache: Prefer node_modules/.cache if exists

  • Use native ESM import for built-ins

  • Respect interopDefault in babel transform

  • Split cache based on interopDefault

  • Remove extention from cache path

  • Properly resolve .mts/.cts with .mjs/.cjs imports

  • resolve: Make sure parentURL is a dir

  • Handle global URL instance mismatch

  • Optional access to Reflect.metadata for typescript decorators

  • Only pass paths option to native require.resolve

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.