{"id":13469561,"url":"https://github.com/unjs/jiti","last_synced_at":"2025-05-14T07:01:44.605Z","repository":{"id":41051088,"uuid":"270135001","full_name":"unjs/jiti","owner":"unjs","description":"Runtime TypeScript and ESM support for Node.js","archived":false,"fork":false,"pushed_at":"2025-03-27T14:42:06.000Z","size":1807,"stargazers_count":2247,"open_issues_count":21,"forks_count":74,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-05-07T06:18:28.120Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-06T23:34:34.000Z","updated_at":"2025-05-05T19:16:50.000Z","dependencies_parsed_at":"2023-10-18T02:31:13.906Z","dependency_job_id":"e52d7078-0e9a-488e-b66d-f921962e2550","html_url":"https://github.com/unjs/jiti","commit_stats":{"total_commits":511,"total_committers":34,"mean_commits":"15.029411764705882","dds":"0.31506849315068497","last_synced_commit":"ad6191f04624badf2112651217bc17008a9bde50"},"previous_names":[],"tags_count":99,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fjiti","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fjiti/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fjiti/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fjiti/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unjs","download_url":"https://codeload.github.com/unjs/jiti/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252992678,"owners_count":21837166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T15:01:44.910Z","updated_at":"2025-05-14T07:01:44.563Z","avatar_url":"https://github.com/unjs.png","language":"TypeScript","readme":"# jiti\n\n\u003c!-- automd:badges color=F0DB4F bundlephobia --\u003e\n\n[![npm version](https://img.shields.io/npm/v/jiti?color=F0DB4F)](https://npmjs.com/package/jiti)\n[![npm downloads](https://img.shields.io/npm/dm/jiti?color=F0DB4F)](https://npmjs.com/package/jiti)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/jiti?color=F0DB4F)](https://bundlephobia.com/package/jiti)\n\n\u003c!-- /automd --\u003e\n\n\u003e This is the active development branch. Check out [jiti/v1](https://github.com/unjs/jiti/tree/v1) for legacy v1 docs and code.\n\n## 🌟 Used in\n\n[Docusaurus](https://docusaurus.io/), [ESLint](https://github.com/eslint/eslint), [FormKit](https://formkit.com/), [Histoire](https://histoire.dev/), [Knip](https://knip.dev/), [Nitro](https://nitro.unjs.io/), [Nuxt](https://nuxt.com/), [PostCSS loader](https://github.com/webpack-contrib/postcss-loader), [Rsbuild](https://rsbuild.dev/), [Size Limit](https://github.com/ai/size-limit), [Slidev](https://sli.dev/), [Tailwindcss](https://tailwindcss.com/), [Tokenami](https://github.com/tokenami/tokenami), [UnoCSS](https://unocss.dev/), [WXT](https://wxt.dev/), [Winglang](https://www.winglang.io/), [Graphql code generator](https://the-guild.dev/graphql/codegen), [Lingui](https://lingui.dev/), [Scaffdog](https://scaff.dog/), [Storybook](https://storybook.js.org), [...UnJS ecosystem](https://unjs.io/), [...60M+ npm monthly downloads](https://npm.chart.dev/jiti), [...6M+ public repositories](https://github.com/unjs/jiti/network/dependents).\n\n## ✅ Features\n\n- Seamless TypeScript and ESM syntax support for Node.js\n- Seamless interoperability between ESM and CommonJS\n- Asynchronous API to replace `import()`\n- Synchronous API to replace `require()` (deprecated)\n- Super slim and zero dependency\n- Custom resolve aliases\n- Smart syntax detection to avoid extra transforms\n- Node.js native `require.cache` integration\n- Filesystem transpile with hard disk caches\n- ESM Loader support\n- JSX support (opt-in)\n\n\u003e [!IMPORTANT]\n\u003e To enhance compatibility, jiti `\u003e=2.1` enabled [`interopDefault`](#interopdefault) using a new Proxy method. If you migrated to `2.0.0` earlier, this might have caused behavior changes. In case of any issues during the upgrade, please [report](https://github.com/unjs/jiti/issues) so we can investigate to solve them. 🙏🏼\n\n## 💡 Usage\n\n### CLI\n\nYou can use `jiti` CLI to quickly run any script with TypeScript and native ESM support!\n\n```bash\nnpx jiti ./index.ts\n```\n\n### Programmatic\n\nInitialize a jiti instance:\n\n```js\n// ESM\nimport { createJiti } from \"jiti\";\nconst jiti = createJiti(import.meta.url);\n\n// CommonJS (deprecated)\nconst { createJiti } = require(\"jiti\");\nconst jiti = createJiti(__filename);\n```\n\nImport (async) and resolve with ESM compatibility:\n\n```js\n// jiti.import(id) is similar to import(id)\nconst mod = await jiti.import(\"./path/to/file.ts\");\n\n// jiti.esmResolve(id) is similar to import.meta.resolve(id)\nconst resolvedPath = jiti.esmResolve(\"./src\");\n```\n\nIf you need the default export of module, you can use `jiti.import(id, { default: true })` as shortcut to `mod?.default ?? mod`.\n\n```js\n// shortcut to mod?.default ?? mod\nconst modDefault = await jiti.import(\"./path/to/file.ts\", { default: true });\n```\n\nCommonJS (sync \u0026 deprecated):\n\n```js\n// jiti() is similar to require(id)\nconst mod = jiti(\"./path/to/file.ts\");\n\n// jiti.resolve() is similar to require.resolve(id)\nconst resolvedPath = jiti.resolve(\"./src\");\n```\n\nYou can also pass options as the second argument:\n\n```js\nconst jiti = createJiti(import.meta.url, { debug: true });\n```\n\n### Register global ESM loader\n\nYou can globally register jiti using [global hooks](https://nodejs.org/api/module.html#initialize). (Important: Requires Node.js \u003e 20)\n\n```js\nimport \"jiti/register\";\n```\n\nOr:\n\n```bash\nnode --import jiti/register index.ts\n```\n\n## 🎈 `jiti/native`\n\nYou can alias `jiti` to `jiti/native` to directly depend on runtime's [`import.meta.resolve`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve) and dynamic [`import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) support. This allows easing up the ecosystem transition to runtime native support by giving the same API of jiti.\n\n## ⚙️ Options\n\n### `debug`\n\n- Type: Boolean\n- Default: `false`\n- Environment variable: `JITI_DEBUG`\n\nEnable verbose logging. You can use `JITI_DEBUG=1 \u003cyour command\u003e` to enable it.\n\n### `fsCache`\n\n- Type: Boolean | String\n- Default: `true`\n- Environment variable: `JITI_FS_CACHE`\n\nFilesystem source cache (enabled by default)\n\nBy default (when is `true`), jiti uses `node_modules/.cache/jiti` (if exists) or `{TMP_DIR}/jiti`.\n\n**Note:** It is recommended that this option be enabled for better performance.\n\n### `moduleCache`\n\n- Type: String\n- Default: `true`\n- Environment variable: `JITI_MODULE_CACHE`\n\nRuntime module cache (enabled by default).\n\nDisabling allows editing code and importing the same module multiple times.\n\nWhen enabled, jiti integrates with Node.js native CommonJS cache-store.\n\n### `transform`\n\n- Type: Function\n- Default: Babel (lazy loaded)\n\nTransform function. See [src/babel](./src/babel.ts) for more details\n\n### `sourceMaps`\n\n- Type: Boolean\n- Default `false`\n- Environment variable: `JITI_SOURCE_MAPS`\n\nAdd inline source map to transformed source for better debugging.\n\n### `interopDefault`\n\n- Type: Boolean\n- Default: `true`\n- Environment variable: `JITI_INTEROP_DEFAULT`\n\nJiti combines module exports with the `default` export using an internal Proxy to improve compatibility with mixed CJS/ESM usage. You can check the current implementation [here](https://github.com/unjs/jiti/blob/main/src/utils.ts#L105).\n\n### `alias`\n\n- Type: Object\n- Default: -\n- Environment variable: `JITI_ALIAS`\n\nYou can also pass an object to the environment variable for inline config. Example: `JITI_ALIAS='{\"~/*\": \"./src/*\"}' jiti ...`.\n\nCustom alias map used to resolve IDs.\n\n### `nativeModules`\n\n- Type: Array\n- Default: ['typescript']\n- Environment variable: `JITI_NATIVE_MODULES`\n\nList of modules (within `node_modules`) to always use native `require()` for them.\n\n### `transformModules`\n\n- Type: Array\n- Default: []\n- Environment variable: `JITI_TRANSFORM_MODULES`\n\nList of modules (within `node_modules`) to transform them regardless of syntax.\n\n### `importMeta`\n\nParent module's [`import.meta`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta) context to use for ESM resolution. (only used for `jiti/native` import).\n\n### `tryNative`\n\n- Type: Boolean\n- Default: Enabled if bun is detected\n- Environment variable: `JITI_TRY_NATIVE`\n\nTry to use native require and import without jiti transformations first.\n\n### `jsx`\n\n- Type: Boolean | {options}\n- Default: `false`\n- Environment Variable: `JITI_JSX`\n\nEnable JSX support using [`@babel/plugin-transform-react-jsx`](https://babeljs.io/docs/babel-plugin-transform-react-jsx).\n\nSee [`test/fixtures/jsx`](./test/fixtures/jsx) for framework integration examples.\n\n## Development\n\n- Clone this repository\n- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`\n- Install dependencies using `pnpm install`\n- Run `pnpm dev`\n- Run `pnpm jiti ./test/path/to/file.ts`\n\n## License\n\n\u003c!-- automd:contributors license=MIT author=\"pi0\" --\u003e\n\nPublished under the [MIT](https://github.com/unjs/jiti/blob/main/LICENSE) license.\nMade by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/jiti/graphs/contributors) 💛\n\u003cbr\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/unjs/jiti/graphs/contributors\"\u003e\n\u003cimg src=\"https://contrib.rocks/image?repo=unjs/jiti\" /\u003e\n\u003c/a\u003e\n\n\u003c!-- /automd --\u003e\n\n\u003c!-- automd:with-automd --\u003e\n","funding_links":[],"categories":["TypeScript","others","Runtimes"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fjiti","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funjs%2Fjiti","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fjiti/lists"}