Cannot find name 'useRuntimeConfig'.

Nuxt 3.16.1 + Bun + Docker: Server-side auto-imports not working useRuntimeConfig() shows "Cannot find name" in server API routes despite: ✅ .nuxt/types/nitro-imports.d.ts exists with correct declarations ✅ tsconfig.json includes the nitro-imports file
✅ Client-side auto-imports work fine ✅ defineEventHandler, getQuery auto-import fine Is this a known issue with Nuxt 3.16+ server-side auto-imports? What's the recommended workaround that maintains runtime config single source of truth? Environment: Nuxt 3.16.1, TypeScript 5.8.3, Bun 1.x, Docker container Thanks in advance for any pointers
3 Replies
kapa.ai
kapa.ai3mo ago
Hi @opalepatrick. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the provided knowledge sources, there is no explicit documentation of a known issue with Nuxt 3.16.x where server-side auto-imports like useRuntimeConfig fail specifically in Bun or Docker environments, while other auto-imports (like defineEventHandler) work and the type declarations exist. However, there are some related points and known limitations: - There have been issues in the past where disabling auto-imports or certain package manager settings (like pnpm's shamefully-hoist) caused type errors or missing auto-imports, but these were generally fixed in later versions or were specific to certain configurations, not to Bun or Docker specifically. For example, see this issue about type errors with auto-imports and this one about pnpm hoisting. - The documentation confirms that useRuntimeConfig should be auto-imported and available in server routes without manual import, and that the type declarations are generated in .nuxt/types/nitro-imports.d.ts, which you already have in place. If your IDE or type checker cannot find useRuntimeConfig, it may be a tooling or environment issue rather than a Nuxt core bug for your version. See the official docs on useRuntimeConfig. - There are no recommended workarounds in the official docs for this specific scenario. The standard and recommended way to maintain runtime config as a single source of truth is to define it in nuxt.config.ts under runtimeConfig and access it via useRuntimeConfig in both client and server code. See the runtime config guide. Summary:
The knowledge sources do not explicitly mention a known issue with Nuxt 3.16.x, Bun, and Docker where useRuntimeConfig is not auto-imported server-side while other auto-imports work. The recommended approach remains to use useRuntimeConfig as documented. If the type is missing despite correct setup, it may be an environment or tooling issue outside the scope of the official Nuxt documentation. If you continue to experience this, consider: - Upgrading to a newer Nuxt version if possible, as related auto-import/type issues have been fixed in later releases. - Double-checking your tsconfig paths and Docker/Bun build steps to ensure .nuxt/types is included and up-to-date. - As a temporary workaround, you could manually import useRuntimeConfig from #imports in your server files, but this is not the standard approach and should not be necessary if auto-imports are working as intended. For more on runtime config and auto-imports, see the Nuxt runtime config documentation and auto-imports guide. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@864045024403652619> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
opalepatrick
opalepatrickOP3mo ago
It seems to be something particular to my bun setup - import { useRuntimeConfig } from '#imports' // ❌ Auto-import fails import { $fetch } from '#imports' // ❌ Auto-import fails
import { useStorage } from '#imports' // ❌ Auto-import fails import prisma from '~/server/utils/prisma' // ❌ Auto-import fails

Did you find this page helpful?