Skip to content

refactor(nuxt,nitro): use dev exports for no-build type-checking - #35605

Merged
danielroe merged 7 commits into
mainfrom
refactor/dev-exports
Jul 17, 2026
Merged

danielroe merged 7 commits into
mainfrom
refactor/dev-exports

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

📚 Description

this is a pretty significant change which makes the nuxt monorepo no longer require a build step to do type checking or, indeed, any kind of testing in the repository.

probably more significant for contributors than anyone else, mind you!

@github-actions github-actions Bot added the 5.x label Jul 16, 2026
@danielroe danielroe changed the title refactor(nuxt,nitro): use dev exports for no-build type-checking refactor(nuxt,nitro): use dev exports for no-build type-checking Jul 16, 2026
@coderabbitai

This comment has been minimized.

@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

🧹 Nitpick comments (2)
packages/nitro-server/src/internal.d.ts (1)

1-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add export shapes for the internal virtual modules. These bare declare module stubs make the imports resolve, but they still drop export-shape checking for #internal/*; r.default.fetch(...) and similar calls will stay unchecked unless these modules declare their minimal exports.

🤖 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/nitro-server/src/internal.d.ts` around lines 1 - 12, Replace the
bare module declarations in the internal declaration file with minimal
export-shape declarations for each virtual module, covering the actual default
and named exports consumed by the code. Ensure default exports expose members
such as fetch where applicable, while preserving module resolution for all
listed `#internal` and `#spa-template` modules.
packages/nuxt/src/core/templates.ts (1)

641-647: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider using TYPE_FILENAME_RE to strip the extension.

If any templates output .ts, .mts, or .cjs files, the hardcoded /\.m?js$/ regex will not remove their extensions for the bare specifier. You can reuse the existing TYPE_FILENAME_RE defined earlier in the file to handle all script extensions robustly.

♻️ Proposed refactor
       // declare both extensioned (`#build/foo.mjs`) and bare (`#build/foo`) module specifiers
       const fullSpecifier = join('`#build`', file.filename)
       declarations += 'declare module ' + JSON.stringify(fullSpecifier) + ';\n'
-      const bareSpecifier = fullSpecifier.replace(/\.m?js$/, '')
+      const bareSpecifier = fullSpecifier.replace(TYPE_FILENAME_RE, '')
       if (bareSpecifier !== fullSpecifier) {
         declarations += 'declare module ' + JSON.stringify(bareSpecifier) + ';\n'
       }
🤖 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/nuxt/src/core/templates.ts` around lines 641 - 647, Update the bare
specifier derivation in the module declaration generation block near
fullSpecifier to use the existing TYPE_FILENAME_RE instead of the hardcoded
/\.m?js$/ pattern, ensuring .ts, .mts, .cts, .js, .mjs, and .cjs extensions are
stripped while preserving the fullSpecifier declaration.
🤖 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/nuxt/src/app/components/nuxt-layout.ts`:
- Around line 60-67: Update the layout selection assignment in the Nuxt layout
component so the complete nullish-coalescing expression is cast to LayoutName
after evaluating props.name, route metadata, route rules, and the default.
Preserve the existing precedence and fallback behavior while ensuring
intermediate string values do not violate the LayoutName type.

---

Nitpick comments:
In `@packages/nitro-server/src/internal.d.ts`:
- Around line 1-12: Replace the bare module declarations in the internal
declaration file with minimal export-shape declarations for each virtual module,
covering the actual default and named exports consumed by the code. Ensure
default exports expose members such as fetch where applicable, while preserving
module resolution for all listed `#internal` and `#spa-template` modules.

In `@packages/nuxt/src/core/templates.ts`:
- Around line 641-647: Update the bare specifier derivation in the module
declaration generation block near fullSpecifier to use the existing
TYPE_FILENAME_RE instead of the hardcoded /\.m?js$/ pattern, ensuring .ts, .mts,
.cts, .js, .mjs, and .cjs extensions are stripped while preserving the
fullSpecifier declaration.
🪄 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

Run ID: 85549e44-834e-43cf-ab59-9da6edaccbf1

📥 Commits

Reviewing files that changed from the base of the PR and between 6d9455e and 3d49a87.

⛔ Files ignored due to path filters (8)
  • package.json is excluded by !package.json, !**/package.json
  • packages/kit/package.json is excluded by !**/package.json
  • packages/nitro-server/package.json is excluded by !**/package.json
  • packages/nuxt/package.json is excluded by !**/package.json
  • packages/rspack/package.json is excluded by !**/package.json
  • packages/schema/package.json is excluded by !**/package.json
  • packages/vite/package.json is excluded by !**/package.json
  • packages/webpack/package.json is excluded by !**/package.json
📒 Files selected for processing (87)
  • .github/workflows/autofix-docs.yml
  • .github/workflows/autofix.yml
  • .github/workflows/ci.yml
  • .github/workflows/docs.yml
  • .github/workflows/release.yml
  • packages/nitro-server/src/augments.ts
  • packages/nitro-server/src/index.ts
  • packages/nitro-server/src/internal.d.ts
  • packages/nitro-server/src/runtime/handlers/error.ts
  • packages/nitro-server/src/runtime/handlers/island.ts
  • packages/nitro-server/src/runtime/handlers/renderer.ts
  • packages/nitro-server/src/runtime/plugins/dev-server-logs.ts
  • packages/nitro-server/src/runtime/utils/app-config.ts
  • packages/nitro-server/src/runtime/utils/cache.ts
  • packages/nitro-server/src/runtime/utils/renderer/app.ts
  • packages/nitro-server/src/runtime/utils/renderer/build-files.ts
  • packages/nitro-server/src/runtime/utils/renderer/islands.ts
  • packages/nitro-server/src/runtime/utils/renderer/payload.ts
  • packages/nitro-server/src/templates.ts
  • packages/nitro-server/tsdown.config.ts
  • packages/nuxt/app.d.ts
  • packages/nuxt/src/app/components/client-only.ts
  • packages/nuxt/src/app/components/island-renderer.ts
  • packages/nuxt/src/app/components/nuxt-island.ts
  • packages/nuxt/src/app/components/nuxt-layout.ts
  • packages/nuxt/src/app/components/nuxt-link.ts
  • packages/nuxt/src/app/components/nuxt-route-announcer.ts
  • packages/nuxt/src/app/components/nuxt-teleport-island-component.ts
  • packages/nuxt/src/app/components/server-placeholder.ts
  • packages/nuxt/src/app/components/test-component-wrapper.ts
  • packages/nuxt/src/app/components/utils.ts
  • packages/nuxt/src/app/composables/asyncData.ts
  • packages/nuxt/src/app/composables/cookie.ts
  • packages/nuxt/src/app/composables/error.ts
  • packages/nuxt/src/app/composables/fetch.ts
  • packages/nuxt/src/app/composables/manifest.ts
  • packages/nuxt/src/app/composables/payload.ts
  • packages/nuxt/src/app/composables/router.ts
  • packages/nuxt/src/app/composables/ssr.ts
  • packages/nuxt/src/app/composables/state.ts
  • packages/nuxt/src/app/config.ts
  • packages/nuxt/src/app/entry.ts
  • packages/nuxt/src/app/index.ts
  • packages/nuxt/src/app/nuxt.ts
  • packages/nuxt/src/app/plugins/check-if-layout-used.ts
  • packages/nuxt/src/app/plugins/check-outdated-build.client.ts
  • packages/nuxt/src/app/plugins/dev-server-logs.ts
  • packages/nuxt/src/app/plugins/payload.client.ts
  • packages/nuxt/src/app/plugins/revive-payload.client.ts
  • packages/nuxt/src/app/plugins/revive-payload.server.ts
  • packages/nuxt/src/app/plugins/router.ts
  • packages/nuxt/src/app/plugins/view-transitions.client.ts
  • packages/nuxt/src/app/types.ts
  • packages/nuxt/src/app/types/augments.ts
  • packages/nuxt/src/build-stub-module.d.ts
  • packages/nuxt/src/build-stubs.d.ts
  • packages/nuxt/src/components/runtime/client-component.ts
  • packages/nuxt/src/core/nuxt.ts
  • packages/nuxt/src/core/plugins/plugin-metadata.ts
  • packages/nuxt/src/core/templates.ts
  • packages/nuxt/src/head/runtime/install-client-head.ts
  • packages/nuxt/src/head/runtime/plugins/unhead-stream.client.ts
  • packages/nuxt/src/head/runtime/plugins/unhead.client.ts
  • packages/nuxt/src/pages/runtime/composables.ts
  • packages/nuxt/src/pages/runtime/page-placeholder.ts
  • packages/nuxt/src/pages/runtime/page.ts
  • packages/nuxt/src/pages/runtime/plugins/prefetch.client.ts
  • packages/nuxt/src/pages/runtime/plugins/prerender.server.ts
  • packages/nuxt/src/pages/runtime/plugins/router.ts
  • packages/nuxt/src/pages/runtime/utils.ts
  • packages/nuxt/src/runtime/server/entry.ts
  • packages/nuxt/tsconfig.build.json
  • packages/nuxt/types.dev.d.ts
  • packages/schema/src/config/nitro.ts
  • packages/schema/src/types/schema.ts
  • packages/vite/src/fix-stacktrace.ts
  • scripts/release.ts
  • test/bundle.test.ts
  • test/fixtures/basic-types/app/app-types.ts
  • test/fixtures/basic-types/modules/test/index.ts
  • test/fixtures/basic-types/nuxt.config.ts
  • test/fixtures/minimal-pages/nuxt.config.ts
  • test/fixtures/minimal-types/app-types.ts
  • test/fixtures/minimal-types/nuxt.config.ts
  • test/fixtures/minimal/nuxt.config.ts
  • test/nuxt/client-only.test.ts
  • vitest.config.ts
💤 Files with no reviewable changes (35)
  • packages/nuxt/src/app/components/nuxt-teleport-island-component.ts
  • packages/nitro-server/src/runtime/plugins/dev-server-logs.ts
  • packages/nuxt/src/pages/runtime/plugins/prerender.server.ts
  • packages/nuxt/src/app/plugins/revive-payload.client.ts
  • packages/nuxt/src/app/plugins/dev-server-logs.ts
  • packages/nuxt/src/app/entry.ts
  • packages/nuxt/src/app/composables/fetch.ts
  • packages/nuxt/src/app/config.ts
  • packages/nuxt/src/app/plugins/router.ts
  • packages/nitro-server/src/runtime/utils/cache.ts
  • packages/nuxt/src/app/plugins/check-outdated-build.client.ts
  • packages/nuxt/src/app/composables/cookie.ts
  • packages/nuxt/src/app/composables/payload.ts
  • packages/nuxt/src/components/runtime/client-component.ts
  • packages/nuxt/src/app/components/island-renderer.ts
  • packages/nuxt/src/app/plugins/revive-payload.server.ts
  • packages/nitro-server/src/runtime/utils/app-config.ts
  • packages/nuxt/src/app/composables/state.ts
  • packages/nuxt/src/app/plugins/check-if-layout-used.ts
  • packages/nuxt/src/app/components/nuxt-island.ts
  • packages/nuxt/src/pages/runtime/page-placeholder.ts
  • packages/nuxt/src/app/components/client-only.ts
  • packages/nuxt/src/head/runtime/plugins/unhead-stream.client.ts
  • packages/nuxt/src/app/plugins/view-transitions.client.ts
  • packages/nuxt/src/app/composables/asyncData.ts
  • packages/nuxt/src/app/components/test-component-wrapper.ts
  • packages/nuxt/src/app/composables/ssr.ts
  • packages/vite/src/fix-stacktrace.ts
  • scripts/release.ts
  • packages/nuxt/src/head/runtime/install-client-head.ts
  • test/fixtures/basic-types/nuxt.config.ts
  • packages/nuxt/src/pages/runtime/page.ts
  • packages/nuxt/src/app/types/augments.ts
  • packages/nuxt/src/head/runtime/plugins/unhead.client.ts
  • packages/nuxt/src/app/components/server-placeholder.ts

Comment on lines +60 to +67
type LayoutName = keyof NuxtLayouts | false | 'default'
let layout: LayoutName = unref(props.name as LayoutName) ?? route?.meta.layout as string ?? routeRulesMatcher(route?.path).appLayout ?? 'default'
if (layout && !(layout in layouts)) {
if (import.meta.dev && layout !== 'default') {
console.warn(`[nuxt] Invalid layout \`${layout}\` selected.`)
}
if (props.fallback) {
layout = unref(props.fallback)
layout = unref(props.fallback as MaybeRef<LayoutName>)

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 | 🟡 Minor | ⚡ Quick win

Fix potential TypeScript error with LayoutName type assignment.

Assigning a string (from route?.meta.layout as string and routeRulesMatcher().appLayout) to LayoutName will cause a TypeScript compilation error if NuxtLayouts does not have a string index signature. Consider casting the entire evaluated expression to LayoutName.

🐛 Proposed fix
-      let layout: LayoutName = unref(props.name as LayoutName) ?? route?.meta.layout as string ?? routeRulesMatcher(route?.path).appLayout ?? 'default'
+      let layout: LayoutName = (unref(props.name) ?? route?.meta.layout ?? routeRulesMatcher(route?.path).appLayout ?? 'default') as LayoutName
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type LayoutName = keyof NuxtLayouts | false | 'default'
let layout: LayoutName = unref(props.name as LayoutName) ?? route?.meta.layout as string ?? routeRulesMatcher(route?.path).appLayout ?? 'default'
if (layout && !(layout in layouts)) {
if (import.meta.dev && layout !== 'default') {
console.warn(`[nuxt] Invalid layout \`${layout}\` selected.`)
}
if (props.fallback) {
layout = unref(props.fallback)
layout = unref(props.fallback as MaybeRef<LayoutName>)
type LayoutName = keyof NuxtLayouts | false | 'default'
let layout: LayoutName = (unref(props.name) ?? route?.meta.layout ?? routeRulesMatcher(route?.path).appLayout ?? 'default') as LayoutName
if (layout && !(layout in layouts)) {
if (import.meta.dev && layout !== 'default') {
console.warn(`[nuxt] Invalid layout \`${layout}\` selected.`)
}
if (props.fallback) {
layout = unref(props.fallback as MaybeRef<LayoutName>)
🤖 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/nuxt/src/app/components/nuxt-layout.ts` around lines 60 - 67, Update
the layout selection assignment in the Nuxt layout component so the complete
nullish-coalescing expression is cast to LayoutName after evaluating props.name,
route metadata, route rules, and the default. Preserve the existing precedence
and fallback behavior while ensuring intermediate string values do not violate
the LayoutName type.

@codspeed

codspeed Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 22.02%

⚠️ 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

⚡ 1 improved benchmark
✅ 20 untouched benchmarks
⏩ 3 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ loadNuxtConfig in the minimal test fixture 14.5 ms 11.8 ms +22.02%

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 refactor/dev-exports (596cf52) with main (2e10cc4)

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. ↩

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

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

@nuxt/nitro-server

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: 596cf52

@danielroe
danielroe merged commit b5b4b0e into main Jul 17, 2026
63 of 70 checks passed
@danielroe
danielroe deleted the refactor/dev-exports branch July 17, 2026 09:10
This was referenced Jul 17, 2026
@github-actions github-actions Bot mentioned this pull request Jul 17, 2026
@github-actions github-actions Bot mentioned this pull request Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant