Skip to content

feat: add jiti/static export#430

Merged
pi0 merged 1 commit into
mainfrom
build/static
Mar 10, 2026
Merged

feat: add jiti/static export#430
pi0 merged 1 commit into
mainfrom
build/static

Conversation

@pi0

@pi0 pi0 commented Feb 27, 2026

Copy link
Copy Markdown
Member

Adds a new jiti/static export that statically imports babel.cjs instead of lazy-loading it via createRequire(import.meta.url).

Closes #417

This solves two use cases:

  • Bun compiled binaries: ensures babel.cjs gets bundled into the binary
  • Webpack/bundler compatibility: the lazy createRequire(import.meta.url) pattern breaks when bundlers rewrite import.meta.url to a hardcoded path. A static import lets bundlers resolve and include babel.cjs correctly.

Usage:

import { createJiti } from "jiti/static";

Based on badlogic@800a4fc

Co-authored-by: Mario Zechner badlogicgames@gmail.com

Static import of babel.cjs for Bun compiled binary support.

Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
@coderabbitai

coderabbitai Bot commented Feb 27, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

A new static bootstrap module is added to lib/jiti-static.mjs that statically imports pre-bundled Babel and JITI runtimes, with a createJiti factory function that delegates to the core JITI runtime. Corresponding export entries are added to package.json.

Changes

Cohort / File(s) Summary
Static Bootstrap Module
lib/jiti-static.mjs
New module that wires pre-bundled Babel transformer and JITI runtime, defines error handler and native import wrapper, exports createJiti factory function that defaults opts.transform to the bundled Babel transformer before delegating to _createJiti.
Package Exports
package.json
Added new "./static" export entry pointing to lib/jiti-static.mjs with types at lib/jiti.d.mts; added corresponding "static" entry to typesVersions map for type resolution.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A static path through Bun we pave,
With Babel bundled, bundled and brave,
Pre-wired and ready, no runtime wait,
JITI static makes code load great!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a new 'jiti/static' export to the package. It is concise, specific, and clearly summarizes the primary objective of the pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch build/static

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pi0 pi0 marked this pull request as ready for review February 27, 2026 13:54
@pi0 pi0 merged commit 5d552e3 into main Mar 10, 2026
8 checks passed
@aryaemami59 aryaemami59 deleted the build/static branch March 10, 2026 21:58
@RaphaelDDL

RaphaelDDL commented Apr 15, 2026

Copy link
Copy Markdown

Hi @pi0 , can we have a release for this please?

jiti going from 2.5.1 to 2.6.1 (e.g. from nuxt/kit, that comes with nuxt/test-utils) when running npm audit fix to fix vulnerabilities, bumps jiti thus makes running Nuxt break with the Cannot find module '../dist/babel.cjs' error.

(btw, I'm not using bun nor webpack, it's just default nuxt with vite and nuxi so not even sure if that new import will fix, since I can't change nuxt/kit way of import)

@iivvaannxx

Copy link
Copy Markdown

@pi0 sorry for the ping, would like to have this released too please 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make babel transform lazy loading optional

3 participants