Nuxt · Architecture

NUXT0108Do not import app code into server code

Report runtime imports in Nuxt server code that resolve to app code: ~/, @/, ~~/app/, @@/app/, relative paths, and layer or manifest aliases.

Why it happens

Nuxt's import protection only rejects #app in server code. Importing an app module from server/ builds without a warning and Nitro bundles it into the server output. App code can rely on Nuxt's app auto-imports, plugins and browser APIs, which the server does not have, and it couples server code to the app's internals. Code used by both sides belongs in shared/utils/, which Nuxt auto-imports in both the app and the server.

Fix

Move code used by both the server and the app to shared/utils/. Keep code that needs the Vue app in app/.

Example

Share utilities through shared/utils

Before

// server/api/cart.get.ts
import { formatPrice } from '~/utils/format'

After

// shared/utils/format.ts
export const formatPrice = (cents: number) => (cents / 100).toFixed(2)

// server/api/cart.get.ts: auto-imported
export default defineEventHandler(() => formatPrice(1999))

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm nuxt doctor --rules nuxt/structure/no-app-code-in-server
Copyright © 2026