jiti (unjs/jiti) — Runtime TypeScript and ESM support for Node.js.
Zero-dependency, slim runtime that provides seamless TypeScript/ESM/CJS interop. All dependencies (including Babel) are bundled into the dist output — the published package has zero runtime dependencies. Used by Nuxt, Tailwind, ESLint, Docusaurus, and 300M+ monthly npm downloads.
Important
Keep AGENTS.md updated with project status.
| File | Purpose |
|---|---|
jiti.ts |
Main entry — createJiti() factory, configures options and returns jiti instance |
eval.ts |
Evaluates transformed code (both sync require and async import) |
require.ts |
Sync require() replacement with CJS/ESM interop |
resolve.ts |
Module resolution with alias support |
transform.ts |
Orchestrates Babel transformation |
babel.ts |
Babel config and plugin setup (TypeScript, JSX, decorators, etc.) |
cache.ts |
Filesystem transpile cache with etag-based invalidation |
options.ts |
Options normalization and defaults |
utils.ts |
Helpers (debug logging, readFile, interopDefault proxy, etc.) |
types.ts |
Core type definitions |
plugins/ |
Babel plugins for import.meta.env, import.meta.url/dirname/filename, import.meta.resolve |
- Bundler: rspack (
rspack.config.mjs) — bundlessrc/→dist/jiti.cjs+dist/babel.cjs - Babel is lazy-loaded from
dist/babel.cjsonly when transformation is needed lib/contains thin ESM/CJS wrappers, CLI, register hook, and type declarations (not bundled, shipped as-is)
jiti(main) — CJS + ESM dual exportjiti/register— Node.js ESM loader hook (--import jiti/register)jiti/native— Uses Node.js native--experimental-strip-typeswhen availablejitiCLI binary —lib/jiti-cli.mjs
- Framework: vitest (
vitest.config.ts) - Main test:
test/fixtures.test.ts— runs each fixture intest/fixtures/via jiti - Other tests:
test/utils.test.ts,test/node-register.test.mjs,test/bun.test.ts - Native runtime tests:
test/native/(node, bun, deno) - Snapshots:
test/__snapshots__/
# Single test file (preferred)
pnpm vitest run test/fixtures.test.ts
# Node register test
pnpm test:node-register
# Native runtime tests
pnpm test:native:node
pnpm test:native:bun
pnpm test:native:deno
# Full suite
pnpm testpnpm build # Clean + rspack bundle
pnpm dev # Watch mode
pnpm lint # ESLint + Prettier
pnpm lint:fix # Auto-fix
pnpm test # Full test suite (lint + types + vitest + register + bun + native)
pnpm test:types # tsgo --noEmitTest fixtures in test/fixtures/<name>/ each have an index.ts (or similar entry).
The fixture test runner executes them via jiti and snapshots stdout.
- Package manager: pnpm
- Node version: see
.nvmrc - Type checking uses
tsgo(TypeScript native preview) - Babel plugins are bundled into
dist/babel.cjsand lazy-loaded stubs/provides lightweight shims for heavy Babel packages to reduce bundle size