Skip to content

fix(cloudflare): use explicit imports in dev plugin instead of #imports#4009

Open
vinayakkulkarni wants to merge 1 commit intonitrojs:v2from
vinayakkulkarni:fix/cloudflare-dev-imports
Open

fix(cloudflare): use explicit imports in dev plugin instead of #imports#4009
vinayakkulkarni wants to merge 1 commit intonitrojs:v2from
vinayakkulkarni:fix/cloudflare-dev-imports

Conversation

@vinayakkulkarni
Copy link

Summary

The Cloudflare dev plugin (plugin.dev.ts) imports useRuntimeConfig and getRequestURL from #imports, which is a virtual module that depends on Nitro's auto-import system being enabled.

When used with Nuxt's compatibilityVersion: 5 (which sets nitroAutoImports: false by default), the #imports virtual module is never created, causing the dev server to fail:

[nitro] ERROR Error: Could not load .nuxt/imports
  (imported by nitropack/dist/presets/cloudflare/runtime/plugin.dev.mjs):
  ENOENT: no such file or directory, open '.nuxt/imports'

Root Cause

  1. Nuxt compatibilityVersion: 5 defaults nitroAutoImports to false (source)
  2. This passes imports: false to Nitro, disabling the unimport system entirely
  3. The #imports virtual module (nitro.options.virtual["#imports"]) relies on nitro.unimport?.toExports() which returns empty or is never registered
  4. The Cloudflare dev plugin is the only preset plugin in Nitro that imports from #imports — all other 50+ preset plugins don't use it

Fix

Replace #imports with explicit imports from nitropack/runtime and h3, consistent with how other Nitro runtime files already import these utilities:

- // @ts-ignore
- import { useRuntimeConfig, getRequestURL } from "#imports";
+ import { useRuntimeConfig } from "nitropack/runtime";
+ import { getRequestURL } from "h3";

Also updated NitroAppPlugin type import from "nitropack" to "nitropack/types" for consistency with other runtime files (e.g., src/runtime/internal/plugin.ts).

Reproduction

Minimal config that triggers the bug (all three required):

export default defineNuxtConfig({
  future: { compatibilityVersion: 5 },
  compatibilityDate: 'latest',
  nitro: { preset: 'cloudflare-pages' },
});

Workaround (until this fix is released):

export default defineNuxtConfig({
  experimental: {
    nitroAutoImports: true, // Override the v5 default
  },
});

Closes nuxt/nuxt#34282

…rts`

The cloudflare dev plugin (`plugin.dev.ts`) imports `useRuntimeConfig` and
`getRequestURL` from `#imports`, which is a virtual module that depends on
Nitro's auto-import system being enabled.

When used with Nuxt's `compatibilityVersion: 5` (which sets
`nitroAutoImports: false` by default), the `#imports` virtual module is
never created, causing the dev server to fail with:

  Error: Could not load .nuxt/imports
  (imported by nitropack/dist/presets/cloudflare/runtime/plugin.dev.mjs):
  ENOENT: no such file or directory

Replace `#imports` with explicit imports from `nitropack/runtime` and `h3`,
consistent with how `defineNitroPlugin` is already imported from
`nitropack/runtime` in other runtime files.

Closes nuxt/nuxt#34282
@vinayakkulkarni vinayakkulkarni requested a review from pi0 as a code owner February 8, 2026 16:37
@vercel
Copy link

vercel bot commented Feb 8, 2026

@vinayakkulkarni is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Feb 8, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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.

1 participant