Runtime TypeScript and ESM support for Node.js with seamless interoperability between ESM and CommonJS.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Core jiti instance creation with comprehensive configuration options for caching, transformation, and module handling.
Creates a new jiti instance with custom options for runtime TypeScript and ESM support.
/**
* Creates a new Jiti instance with custom options.
* @param id - Instance id, usually the current filename or import.meta.url
* @param userOptions - Custom options to override the default options
* @returns A Jiti instance with configured behavior
*/
function createJiti(id: string, userOptions?: JitiOptions): Jiti;Usage Examples:
import { createJiti } from "jiti";
// Basic usage with current file URL
const jiti = createJiti(import.meta.url);
// With custom options
const jiti = createJiti(import.meta.url, {
debug: true,
fsCache: false,
jsx: true
});
// CommonJS usage (deprecated)
const { createJiti } = require("jiti");
const jiti = createJiti(__filename);Complete configuration interface for customizing jiti behavior.
interface JitiOptions {
/**
* Filesystem source cache - enables caching transformed files to disk
* @default true
*/
fsCache?: boolean | string;
/**
* Rebuild the filesystem source cache
* @default false
*/
rebuildFsCache?: boolean;
/**
* Runtime module cache - integrates with Node.js require.cache
* @default true
*/
moduleCache?: boolean;
/**
* Enable verbose debugging output
* @default false
*/
debug?: boolean;
/**
* Enable sourcemaps for transformed code
* @default false
*/
sourceMaps?: boolean;
/**
* Enable default export interoperability using Proxy
* @default true
*/
interopDefault?: boolean;
/**
* Supported file extensions for transformation
* @default [".js", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts", ".mtsx", ".ctsx", ".json"]
*/
extensions?: string[];
/**
* Custom transform function for source code
*/
transform?: (opts: TransformOptions) => TransformResult;
/**
* Transform options passed to the transform function
*/
transformOptions?: Omit<TransformOptions, "source">;
/**
* Resolve aliases for module paths
* @default {}
*/
alias?: Record<string, string>;
/**
* Modules to always use native require/import for
* @default ["typescript", "jiti"]
*/
nativeModules?: string[];
/**
* Modules to transform regardless of syntax
* @default []
*/
transformModules?: string[];
/**
* Parent module's import.meta context for ESM resolution
*/
importMeta?: ImportMeta;
/**
* Try native require/import before jiti transformations
* @default false (true if Bun is detected)
*/
tryNative?: boolean;
/**
* Enable JSX support using @babel/plugin-transform-react-jsx
* @default false
*/
jsx?: boolean | JSXOptions;
/**
* @deprecated Use the fsCache option instead
* @default true
*/
cache?: boolean | string;
/**
* @deprecated Use the moduleCache option instead
* @default true
*/
requireCache?: boolean;
/**
* Internal cache version for filesystem cache
* @internal
*/
cacheVersion?: string;
}All options can be configured via environment variables for convenient runtime configuration.
Environment Variables:
JITI_DEBUG - Enable debug logging (boolean)JITI_FS_CACHE - Filesystem cache setting (boolean/string)JITI_REBUILD_FS_CACHE - Rebuild cache flag (boolean)JITI_MODULE_CACHE - Module cache setting (boolean)JITI_SOURCE_MAPS - Source maps setting (boolean)JITI_INTEROP_DEFAULT - Default interop setting (boolean)JITI_ALIAS - Resolve aliases (JSON string)JITI_NATIVE_MODULES - Native modules list (JSON string)JITI_TRANSFORM_MODULES - Transform modules list (JSON string)JITI_TRY_NATIVE - Try native first setting (boolean)JITI_JSX - JSX support setting (boolean)Usage Examples:
# Enable debug mode and JSX support
JITI_DEBUG=1 JITI_JSX=1 node script.js
# Set custom aliases
JITI_ALIAS='{"@/*": "./src/*", "~/*": "./lib/*"}' node script.js
# Disable caching for development
JITI_FS_CACHE=false JITI_MODULE_CACHE=false node script.jsAdvanced JSX transformation options using Babel's React JSX plugin.
interface JSXOptions {
/**
* Throw error if JSX namespace is used
* @default false
*/
throwIfNamespace?: boolean;
/**
* JSX runtime mode - 'classic' uses React.createElement, 'automatic' uses new JSX transform
* @default 'classic'
*/
runtime?: "classic" | "automatic";
/**
* Import source for automatic runtime
* @default 'react'
*/
importSource?: string;
/**
* JSX pragma function for classic runtime
* @default 'React.createElement'
*/
pragma?: string;
/**
* JSX fragment pragma for classic runtime
* @default 'React.Fragment'
*/
pragmaFrag?: string;
/**
* Use built-in helpers for JSX
* @default false
*/
useBuiltIns?: boolean;
/**
* Use spread syntax for props
* @default false
*/
useSpread?: boolean;
}Usage Examples:
// Enable JSX with default React settings
const jiti = createJiti(import.meta.url, { jsx: true });
// Custom JSX configuration for Preact
const jiti = createJiti(import.meta.url, {
jsx: {
runtime: "automatic",
importSource: "preact"
}
});
// Classic JSX with custom pragma
const jiti = createJiti(import.meta.url, {
jsx: {
runtime: "classic",
pragma: "h",
pragmaFrag: "Fragment"
}
});jiti provides multiple caching strategies for optimal performance:
Filesystem Cache:
node_modules/.cache/jiti or temp directoryModule Cache:
require.cacheUsage Examples:
// Custom filesystem cache directory
const jiti = createJiti(import.meta.url, {
fsCache: "./custom-cache"
});
// Disable all caching for development
const jiti = createJiti(import.meta.url, {
fsCache: false,
moduleCache: false
});
// Force cache rebuild
const jiti = createJiti(import.meta.url, {
rebuildFsCache: true
});