#36404·nuxt

`nuxt dev` answers every SSR request with `Cannot find module 'ofetch'` from `fetch.server.mjs` when the first request arrives during warm-up (pnpm isolated linker)

Author: denismrteCreated Sep 24, 2026Updated Sep 24, 2026
Labelsnitro5.xpossible regression

Environment

Operating system macOS 27.0.0, arm64
Node.js v24.19.0
Package manager pnpm 11.22.0, default node-linker (isolated)
Nuxt [email protected] (current main) and 5.0.0-29835210.f258408a
Nitro 3.0.260903-beta
Builder vite 8.3.0
nuxt/cli 4.0.0-20260922-145010-cf0e756 (what the nightly installs today) and 4.0.0-20260820-224244-a3dee96

Reproduction

Self-contained — three files and a script, no repository needed. Run it in a directory with no node_modules/ofetch in any parent directory (see Additional context).

package.json

json
{
  "private": true,
  "type": "module",
  "dependencies": {
    "nuxt": "npm:[email protected]",
    "vue": "3.5.43",
    "vue-router": "5.3.1"
  }
}

nuxt.config.ts

typescript
export default defineNuxtConfig({
  devtools: { enabled: false },
  telemetry: false,
})

app/app.vue

xml
<template>
  <p>hello</p>
</template>

repro.sh

bash
#!/bin/sh
# Cold-starts `nuxt dev` and sends GET / every 50 ms from launch; prints the first answer that is
# not 503 (the loading page), then a later one. DELAY=6 waits six seconds before the first request.
PORT=${PORT:-4611}
rm -rf .nuxt node_modules/.cache
./node_modules/.bin/nuxt dev --port "$PORT" > dev.log 2>&1 &
sleep "${DELAY:-0}"
while :; do
  code=$(curl -s -o /dev/null -w '%{http_code}' "http://localhost:$PORT/")
  [ "$code" != 000 ] && [ "$code" != 503 ] && break
  sleep 0.05
done
echo "first answer: $code"
sleep 2
echo "later answer: $(curl -s -o /dev/null -w '%{http_code}' "http://localhost:$PORT/")"
kill $!
bash
pnpm install
./repro.sh           # first answer: 500 / later answer: 500
DELAY=6 ./repro.sh   # first answer: 200 / later answer: 200

Describe the bug

When the first request reaches nuxt dev while it is still warming up, every SSR request fails with Cannot find module 'ofetch' imported from 'virtual:nuxt:.nuxt%2Ffetch.server.mjs' for the rest of the process's life (still 500 a minute later here). A restart recovers only when its first request comes late: a first request a few seconds after launch gets 200, and so does the production build.

Measured with a harness equivalent to repro.sh (cold start each time, starts interleaved across versions, two series):

version early first request first request after 6 s
5.0.0-29836693.3006e5ac (main) 500 in 20 of 20 200 in 3 of 3
5.0.0-29835210.f258408a 500 in 20 of 20 200 in 3 of 3
5.0.0-29815057.84261aa3 (#36318) 500 in 5 of 5 —
5.0.0-29814795.2923df84 (its parent) 200 in 5 of 5 —
5.0.0-29787188.1d507ee7 200 in 20 of 20 200 in 3 of 3
f258408a + publicHoistPattern: ['ofetch'] 200 in 20 of 20 —
f258408a + ofetch as a direct dependency 200 in 5 of 5 —

It starts at #36318 (84261aa3, the Nitro v2 compatibility layer): packages/nitro-server/src/runtime/compat/decorate.ts imports createFetch from ofetch, and handlers/renderer.ts imports decorateLegacyEvent from it. Both lines are unchanged on main.

The mechanism, as far as I can trace it:

  1. Vite caches the dev SSR externalization verdict per specifier, not per importer (createIsExternal in packages/vite/src/node/external.ts: processedIds is keyed by the bare id, and isExternalizable resolves it from whichever importer asks first).
  2. If @nuxt/nitro-server's runtime/compat/decorate.mjs is analysed first, ofetch resolves from inside that package and is cached as external.
  3. The virtual fetch.server.mjs template (import { createFetch } from 'ofetch') then keeps a bare external import. Its importer is virtual, so the module runner resolves ofetch from the project root, where pnpm's isolated linker puts no ofetch — ERR_MODULE_NOT_FOUND.
  4. If fetch.server.mjs is analysed first, ofetch does not resolve from the root, is cached as not external, and every importer's ofetch is resolved to a file and inlined — the virtual one through nuxt:resolve-bare-imports, from Nuxt's own directory. That was the only order before #36318, and it is still the order when the first request comes late.

A transform trace (a transform/resolveId logger added with addVitePlugin, times from module setup) shows the two orders on f258408a:

early first request -> 500
  508ms env=ssr @nuxt/nitro-server-nightly/dist/runtime/compat/decorate.mjs
  755ms env=ssr virtual:nuxt:.nuxt%2Ffetch.server.mjs
  (no resolveId call for 'ofetch' in the ssr environment: both imports were externalized)

first request after 6 s -> 200
  304ms env=ssr virtual:nuxt:.nuxt%2Ffetch.server.mjs
  313ms resolveId 'ofetch' env=ssr importer=virtual:nuxt:.nuxt%2Ffetch.server.mjs
  576ms env=ssr @nuxt/nitro-server-nightly/dist/runtime/compat/decorate.mjs
  579ms resolveId 'ofetch' env=ssr importer=.../runtime/compat/decorate.mjs

Additional context

  • A node_modules/ofetch in any parent directory hides the bug: the root resolution walks up and finds it. The same app placed under a directory whose node_modules had ofetch answered 200 in 5 of 5 early starts.
  • @nuxt/nitro-server already lists ofetch in nitroImplicitDependencies and routes those specifiers to Nitro's copy through a resolveId fallback for package managers that do not hoist. An import Vite has already externalized never reaches a resolveId hook: Vite's fetchModule resolves it with tryNodeResolve from the importer, and a virtual importer falls back to the project root.
  • Workarounds that hold here: publicHoistPattern: ['ofetch'] in pnpm-workspace.yaml, or ofetch as a direct dependency.
  • The production build is unaffected: early requests to node .output/server/index.mjs answer 200 (3 of 3), with ofetch bundled into the SSR chunk.

Logs

shell-script
◆  Ready in 309ms
│  config 71ms · modules 15ms · app 56ms · types 113ms · bundle 10ms · server 44ms
[log] [log] [request error] [GET] http://localhost:4611/

✖ HTTPError [ERR_MODULE_NOT_FOUND] (500): Cannot find module 'ofetch' imported from
  'virtual:nuxt:.nuxt%2Ffetch.server.mjs'

  … 10 dependency frames