Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Nuxt 5 server imports (nitro, h3) fail under pnpm's default non-hoisted layout #35375

Description

@JakeIsMeh

Environment

Operating system Windows 10.0.26200
CPU AMD Ryzen 9 7900X 12-Core Processor (24 cores)
Node.js version v26.3.0
nuxt/cli version 3.35.2
Package manager [email protected]
Nuxt version 5.0.0-29689124.2f9ee7b5
Nitro version 3.0.260522-beta
Builder [email protected]
Config compatibilityDate, devtools
Modules -

Reproduction

https://stackblitz.com/edit/github-7o3sknxd
(the stackbiltz doesn't work, it's pinned to pnpm 8 for some reason)

  1. Initialize a Nuxt 5 project using pnpm (default configuration).
  2. Create any server file (e.g., server/api/test.ts or a server plugin) that imports from nitro or h3 (e.g., import { useRuntimeConfig } from 'nitro/runtime-config', import { defineHandler } from 'h3').
  3. Attempt to build or start the dev server: compilation fails with unresolved imports.
  4. Add nitro/h3 to the project's dependencies/devDependencies to resolve the import.
  5. Run the dev server: the imports resolve, but runtime features like virtual modules/configs break due to the duplicate package instance.

Describe the bug

Nuxt 5 server-side code (plugins, routes, middleware) fails to resolve imports from nitro or h3 (including direct imports like h3's defineHandler or Nitro auto-imports) when using pnpm's default isolated (shamefully-hoist=false) layout.

If a user adds nitro or h3 to their project's package.json to fix the resolution error, pnpm installs a duplicate peer-resolved instance. This duplicate package bypasses Nitro's builder/plugin context, triggering virtual module stub warnings (e.g., Nitro runtime imports detected without a builder or Nitro plugin. A stub implementation will be used.) and breaking features like useRuntimeConfig().

Additional context

Currently, the only working setup with pnpm is forcing shamefully-hoist=true and not having nitro/h3 in package.json.

Since Nuxt 5/Nitro 3 expects user code to import/use symbols from nitro and h3, either @nuxt/nitro-server declares them as peerDependencies, or Nuxt should re-export them to support strict package manager layouts.

Logs

Metadata

Metadata

Assignees

Labels

5.xnitroNitro server engine integration

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions