Skip to content

refactor(kit): inline c12 and untyped, make jiti/giget optional peers - #35936

Merged
danielroe merged 7 commits into
mainfrom
perf/kit-jiti
Aug 2, 2026
Merged

danielroe merged 7 commits into
mainfrom
perf/kit-jiti

Conversation

@danielroe

@danielroe danielroe commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

🔗 Linked issue

📚 Description

there are some unjs packages that have multiple purposes. for example, c12 supports watching a config file and brings in chokidar and other deps; untyped pulls in babel

this allows us to move jiti + giget to be optional peer dependencies. we are advising users to manage remote layers through their package manager; they can still add giget manually if they want the previous behaviour.

similarly, we will recommend users to write their nuxt.config.ts and modules in a way that can be imported by node natively, without needing jiti to import it. now that typescript is natively supported, this is relatively straightforward. and for the few edge cases where it isn't, they can install jiti.

this saves us install time (and processing time!) and makes the bare nuxt install slimmer and better for most users

Note

nitro has already made exactly this move, for very similar reasons

@github-actions github-actions Bot added 5.x ♻️ refactor Code restructuring without behavior change labels Aug 1, 2026
@socket-security

socket-security Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedc12@​4.0.0-beta.5991001008780
Addedseroval@​1.6.010010010094100

View full report

@pkg-pr-new

pkg-pr-new Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@35936

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@35936

nuxt

npm i https://pkg.pr.new/nuxt@35936

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@35936

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@35936

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@35936

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@35936

commit: 3b97dba

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The change introduces Nuxt-specific layer and configuration types. It adds optional Giget and project-scoped Jiti resolution. Configuration loading supports native imports, cache busting, custom importers, Jiti fallback, and remote-layer dependency checks. Module loading tries native imports before Jiti and reports dedicated diagnostics. Tests cover dependency resolution and module formats. Documentation describes the remote-layer migration.

Possibly related PRs

  • nuxt/nuxt#35497: Both changes update Nuxt module loading and import failure diagnostics.
  • nuxt/nuxt#35653: Both changes update configuration layer resolution and NUXT_B8020.
  • nuxt/nuxt#35901: Both changes update Jiti loading in module installation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises the main refactor and the move of jiti and giget to optional peer dependencies.
Description check ✅ Passed The description directly explains the dependency changes, native imports, optional jiti and giget use, and the intended installation benefits.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/kit-jiti

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/kit/src/loader/config.ts (1)

257-306: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Pass the required Loader when loading aliased nested configs.

resolveOptions.import is not populated by c12’s resolve context, so the nested loadConfig for alias-prefixed sources uses c12’s own loader instead of this project’s importConfigFile loader. Pass the loader that opts.import ?? importConfigFile resolves to into this nested loadConfig.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/kit/src/loader/config.ts` around lines 257 - 306, Update the
aliased-source branch in the resolve method to pass the configured loader, using
the same opts.import ?? importConfigFile fallback used by the outer load. Do not
rely on resolveOptions.import, since c12 does not populate it; ensure the nested
loadConfig call uses this project loader.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/kit/src/internal/esm.ts`:
- Around line 89-101: Update requireJiti() so its fallback resolves jiti using
CommonJS-specific resolution conditions before passing the result to require().
Preserve the existing rootDir fallback and error propagation, but ensure the
resolved candidate targets jiti’s CJS entry rather than its ESM entry.

In `@packages/kit/src/internal/jiti.ts`:
- Around line 42-67: The loadJiti function does not guard concurrent
installation attempts, allowing multiple callers to invoke
ensureDependencyInstalled for jiti simultaneously. Add an in-flight installation
promise or equivalent per-root/package guard around the
ensureDependencyInstalled call, reuse it for concurrent requests, and preserve
the existing cached resolution and install-disabled behavior.

In `@packages/kit/src/module/install.ts`:
- Around line 374-391: Update describeNativeImportFailure() and the native
import catch in the module installation flow to return and enforce explicit
fallback eligibility, calling getSharedJiti() only for recognized runtime
incompatibilities such as non-erasable syntax, node_modules loading, or
unresolved specifiers. For module evaluation failures, rethrow the original
native error without resolving or installing Jiti, and add a regression test
covering a module that throws during evaluation.

---

Outside diff comments:
In `@packages/kit/src/loader/config.ts`:
- Around line 257-306: Update the aliased-source branch in the resolve method to
pass the configured loader, using the same opts.import ?? importConfigFile
fallback used by the outer load. Do not rely on resolveOptions.import, since c12
does not populate it; ensure the nested loadConfig call uses this project
loader.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e5427801-ec4d-41d1-b519-33cca8c1afc5

📥 Commits

Reviewing files that changed from the base of the PR and between ec5c55e and 42515f4.

⛔ Files ignored due to path filters (3)
  • packages/kit/package.json is excluded by !**/package.json
  • packages/schema/package.json is excluded by !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (16)
  • docs/1.getting-started/18.upgrade.md
  • knip.json
  • packages/kit/src/diagnostics/config.ts
  • packages/kit/src/diagnostics/kit-api.ts
  • packages/kit/src/internal/esm.ts
  • packages/kit/src/internal/jiti.ts
  • packages/kit/src/loader/config.ts
  • packages/kit/src/module/install.ts
  • packages/kit/test/jiti-resolution.spec.ts
  • packages/kit/test/module.test.ts
  • packages/kit/tsdown.config.ts
  • packages/schema/src/index.ts
  • packages/schema/src/types/config.ts
  • packages/schema/src/types/layers.ts
  • packages/schema/src/types/schema.ts
  • pnpm-workspace.yaml

Comment thread packages/kit/src/internal/esm.ts Resolved
Comment thread packages/kit/src/internal/jiti.ts Resolved
Comment thread packages/kit/src/module/install.ts Resolved
@codspeed

codspeed Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 24.13%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 19 untouched benchmarks
⏩ 3 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ loadNuxtConfig in the basic test fixture (types) 22.4 ms 16.2 ms +38.3%
⚡ loadNuxtConfig in the basic test fixture 37 ms 33.2 ms +11.42%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing perf/kit-jiti (3b97dba) with main (8568cd2)2

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (e6509fd) during the generation of this report, so 8568cd2 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/kit/src/internal/jiti.ts`:
- Line 23: Update the Jiti cache used by the initialization logic around cached
and the code at lines 43-52 to key promises by normalized rootDir, searchPaths,
and install policy instead of sharing one process-wide promise. Return the entry
matching each caller’s resolution context, and remove only that context’s cache
entry when initialization fails so other cached resolutions remain unaffected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c69365ad-cc25-4ee8-a4a4-38722dec6040

📥 Commits

Reviewing files that changed from the base of the PR and between 14eb45b and 832533f.

📒 Files selected for processing (2)
  • packages/kit/src/internal/jiti.ts
  • packages/kit/src/module/define.ts

install?: boolean
}

let cached: Promise<JitiModule | undefined> | undefined

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Key the Jiti cache by the resolution context.

Line 44 shares one process-wide promise, but rootDir, searchPaths, and install change the result. If one caller resolves Jiti from project A, a concurrent caller for project B receives project A’s module. If the first caller uses install: false, it can also prevent a concurrent install-enabled caller from installing Jiti.

Cache promises per normalised rootDir, searchPaths, and installation policy. Clear only the failed cache entry.

Also applies to: 43-52

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/kit/src/internal/jiti.ts` at line 23, Update the Jiti cache used by
the initialization logic around cached and the code at lines 43-52 to key
promises by normalized rootDir, searchPaths, and install policy instead of
sharing one process-wide promise. Return the entry matching each caller’s
resolution context, and remove only that context’s cache entry when
initialization fails so other cached resolutions remain unaffected.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/kit/src/internal/jiti.ts`:
- Around line 12-31: Update isLoaderError and its callers in the config and
module loading flows to accept the failed target/specifier and determine whether
native loading rejected that target before evaluation, rather than treating
SyntaxError instances or error codes alone as loader failures. Remove the
unconditional instanceof SyntaxError and code-only checks, preserve retries only
for pre-evaluation loader failures, and add regression coverage for runtime
SyntaxError and top-level dynamic-import rejection cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 842ae44a-258f-4eee-820a-9c14aae13973

📥 Commits

Reviewing files that changed from the base of the PR and between 832533f and 1720024.

⛔ Files ignored due to path filters (26)
  • packages/kit/package.json is excluded by !**/package.json
  • test/fixtures/basic-types/extends/node_modules/foo/nuxt.config.mjs is excluded by !**/node_modules/**
  • test/fixtures/basic-types/package.json is excluded by !**/package.json
  • test/fixtures/basic/extends/node_modules/foo/nuxt.config.mjs is excluded by !**/node_modules/**
  • test/fixtures/basic/package.json is excluded by !**/package.json
  • test/fixtures/build-assets-dir-collision/package.json is excluded by !**/package.json
  • test/fixtures/chunk-error/package.json is excluded by !**/package.json
  • test/fixtures/dynamic-paths/package.json is excluded by !**/package.json
  • test/fixtures/external-vue-resolution/package.json is excluded by !**/package.json
  • test/fixtures/hmr-sibling-layer/package.json is excluded by !**/package.json
  • test/fixtures/hmr/package.json is excluded by !**/package.json
  • test/fixtures/inline-styles/package.json is excluded by !**/package.json
  • test/fixtures/minimal-pages/package.json is excluded by !**/package.json
  • test/fixtures/minimal-types/package.json is excluded by !**/package.json
  • test/fixtures/minimal/package.json is excluded by !**/package.json
  • test/fixtures/nested-suspense/package.json is excluded by !**/package.json
  • test/fixtures/nitro-vite-environment/package.json is excluded by !**/package.json
  • test/fixtures/no-scripts/package.json is excluded by !**/package.json
  • test/fixtures/runtime-compiler/package.json is excluded by !**/package.json
  • test/fixtures/spa-loader/package.json is excluded by !**/package.json
  • test/fixtures/spa/package.json is excluded by !**/package.json
  • test/fixtures/ssr-streaming/package.json is excluded by !**/package.json
  • test/fixtures/suspense-layout/package.json is excluded by !**/package.json
  • test/fixtures/suspense/package.json is excluded by !**/package.json
  • test/fixtures/ui-templates/package.json is excluded by !**/package.json
  • test/fixtures/worker-assets/package.json is excluded by !**/package.json
📒 Files selected for processing (27)
  • packages/kit/src/diagnostics/kit-api.ts
  • packages/kit/src/internal/esm.ts
  • packages/kit/src/internal/jiti.ts
  • packages/kit/src/loader/config.ts
  • packages/kit/src/module/install.ts
  • packages/kit/test/module.test.ts
  • test/fixtures/basic-types/nuxt.config.ts
  • test/fixtures/basic/nuxt.config.ts
  • test/fixtures/build-assets-dir-collision/nuxt.config.ts
  • test/fixtures/dynamic-paths/nuxt.config.ts
  • test/fixtures/hmr/nuxt.config.ts
  • test/fixtures/inline-styles/nuxt.config.ts
  • test/fixtures/lazy-hydration/nuxt.config.ts
  • test/fixtures/nested-suspense/nuxt.config.ts
  • test/fixtures/nitro-vite-environment/nuxt.config.ts
  • test/fixtures/nuxt-time/nuxt.config.ts
  • test/fixtures/payload-cache-leak/nuxt.config.ts
  • test/fixtures/preview/nuxt.config.ts
  • test/fixtures/route-scroll/nuxt.config.ts
  • test/fixtures/runtime-compiler/nuxt.config.ts
  • test/fixtures/server-components/nuxt.config.ts
  • test/fixtures/spa-loader/nuxt.config.ts
  • test/fixtures/ssr-streaming/nuxt.config.ts
  • test/fixtures/suspense-layout/nuxt.config.ts
  • test/fixtures/suspense/nuxt.config.ts
  • test/fixtures/ui-templates/nuxt.config.ts
  • test/fixtures/worker-assets/nuxt.config.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/kit/src/internal/esm.ts
  • packages/kit/src/diagnostics/kit-api.ts
  • packages/kit/src/module/install.ts
  • packages/kit/src/loader/config.ts

Comment thread packages/kit/src/internal/jiti.ts Resolved
@github-actions github-actions Bot mentioned this pull request Aug 28, 2026
@github-actions github-actions Bot mentioned this pull request Oct 5, 2026
onmax added a commit to onmax/nuxt that referenced this pull request Nov 3, 2026
`untyped` was the only package in a default Nuxt 5 install with a hard
dependency on `jiti`, which it uses only in `untyped/loader`. Nuxt imports
the main entry and lazily imports `untyped/babel-plugin`, so it is inlined
into `nuxt` as `@nuxt/kit` already does (nuxt#35936). The babel plugin stays a
separate chunk behind the existing dynamic import.

`@nuxt/schema`'s declarations imported `untyped` types without depending
on it, which only resolved because `nuxt` installed it. Those types are
now bundled into the declarations, and `untyped` is no longer an allowed
external type in the public API check.

The no-jiti suite now also walks the installed `dependencies` of `nuxt`,
since the existing check only looked at direct dependencies.
onmax added a commit to onmax/nuxt that referenced this pull request Nov 5, 2026
`untyped` was the only package in a default Nuxt 5 install with a hard
dependency on `jiti`, which it uses only in `untyped/loader`. Nuxt imports
the main entry and lazily imports `untyped/babel-plugin`, so it is inlined
into `nuxt` as `@nuxt/kit` already does (nuxt#35936). The babel plugin stays a
separate chunk behind the existing dynamic import.

`@nuxt/schema`'s declarations imported `untyped` types without depending
on it, which only resolved because `nuxt` installed it. Those types are
now bundled into the declarations, and `untyped` is no longer an allowed
external type in the public API check.

The no-jiti suite now also walks the installed `dependencies` of `nuxt`,
since the existing check only looked at direct dependencies.
onmax added a commit to onmax/nuxt that referenced this pull request Nov 6, 2026
`untyped` was the only package in a default Nuxt 5 install with a hard
dependency on `jiti`, which it uses only in `untyped/loader`. Nuxt imports
the main entry and lazily imports `untyped/babel-plugin`, so it is inlined
into `nuxt` as `@nuxt/kit` already does (nuxt#35936). The babel plugin stays a
separate chunk behind the existing dynamic import.

`@nuxt/schema`'s declarations imported `untyped` types without depending
on it, which only resolved because `nuxt` installed it. Those types are
now bundled into the declarations, and `untyped` is no longer an allowed
external type in the public API check.

The no-jiti suite now also walks the installed `dependencies` of `nuxt`,
since the existing check only looked at direct dependencies.
danielroe pushed a commit to onmax/nuxt that referenced this pull request Nov 14, 2026
`untyped` was the only package in a default Nuxt 5 install with a hard
dependency on `jiti`, which it uses only in `untyped/loader`. Nuxt uses
only its core (`resolveSchema` and `generateTypes`), so it is inlined into
`nuxt` as `@nuxt/kit` already does (nuxt#35936) and moves to
`devDependencies`.

`@nuxt/schema`'s declarations imported `untyped` types without depending
on it, which only resolved because `nuxt` installed it. Those types are
now bundled into the declarations, and `untyped` is no longer an allowed
external type in the public API check.

The no-jiti suite now also walks the installed `dependencies`,
`optionalDependencies` and required peers of `nuxt`, since the existing
check only looked at direct dependencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x ♻️ refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant