Jiti is a robust utility for Node.js that provides seamless runtime support for both TypeScript and ECMAScript Modules (ESM), along with comprehensive interoperability between ESM and CommonJS. The package is currently at version 2.6.1 and maintains a high release cadence with frequent minor version bumps and patch fixes, indicating active and continuous development. Its key differentiators include a 'zero dependency' footprint, significant performance optimizations (e.g., improved startup times from v2.6.0 onwards), and widespread adoption within prominent projects such as Nuxt, TailwindCSS, ESLint, and Storybook. Jiti offers both an asynchronous (`jiti.import`) and a synchronously (now deprecated `jiti()`) API, alongside a global ESM loader for Node.js versions 20 and above. It simplifies the execution of complex JavaScript ecosystems by handling various module formats and language extensions without requiring explicit build steps.
npm install jitiVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize Jiti for runtime TypeScript and ESM support, dynamically import a module, access both named and default exports, and resolve paths programmatically, including creating and cleaning up a temporary module for a runnable example.
Thoroughly test module imports and exports after upgrading. If issues persist, consider reporting them on the Jiti GitHub repository for investigation.
Refactor synchronous `jiti(id)` calls to `await jiti.import(id)` and ensure your code handles promises appropriately.
Ensure your Node.js environment is version 20 or newer when relying on the global ESM loader. For older Node.js versions, use `createJiti` programmatically.
For new projects, prefer setting up your project as ESM and using `import.meta.url`. If you must use CommonJS, be aware that `__filename` context might receive less future-focused support.
If using Jiti, ensure it's initialized and use `await jiti.import('./path/to/esm-module.mjs')`. Alternatively, enable Jiti's global loader with `node --import jiti/register`.Execute the file using `npx jiti ./your-script.ts` or `node --import jiti/register ./your-script.ts`. If programmatic, ensure `createJiti` is correctly initialized.
Use `const mod = await jiti.import(id); console.log(mod?.default ?? mod);` or leverage the shorthand `const modDefault = await jiti.import(id, { default: true });` for direct default export access.No dependency data recorded yet.