Skip to content

fix(auth): preserve nuxthub db package imports in prerender builds#305

Merged
onmax merged 2 commits intomainfrom
fix/nuxthub-prerender-db-import
Apr 17, 2026
Merged

fix(auth): preserve nuxthub db package imports in prerender builds#305
onmax merged 2 commits intomainfrom
fix/nuxthub-prerender-db-import

Conversation

@onmax
Copy link
Copy Markdown
Collaborator

@onmax onmax commented Apr 17, 2026

Before

Consumer build in node_modules/.cache/nuxt/.nuxt/prerender/index.mjs:

import '../../../../../../../../@nuxthub/db/db.mjs';

Nitro rebases the bare @nuxthub/db specifier to a relative path that escapes the build dir, crashing prerender. Only reproduces when .nuxt/ lives inside node_modules/.cache/nuxt/ (real consumer builds). Reported against pkg.pr.new 9a4ad00, repro: jd-solanki/nuxthub-better-auth-repro@049505f.

Expected

Prerender keeps @nuxthub/db as a bare specifier — NuxtHub writes the physical node_modules/@nuxthub/db/db.mjs and resolves it at runtime.

Change

Mark @nuxthub/db external in Nitro config when hasHubDb, so Rollup stops trying to resolve the bare import during prerender bundling.

nuxt.hook('nitro:config', (nitroConfig) => {
  nitroConfig.externals ||= {}
  nitroConfig.externals.external ||= []
  if (!nitroConfig.externals.external.includes('@nuxthub/db'))
    nitroConfig.externals.external.push('@nuxthub/db')
})
  • regression test (test/nuxthub-prerender-db-import.test.ts) that builds a postgresql fixture and asserts no ../../../../@nuxthub/db escaping path in prerender output.

Validation

  • pnpm test test/nuxthub-prerender-db-import.test.ts
  • pnpm lint, pnpm typecheck, pnpm exec nuxt-module-build build
  • Against jd-solanki/nuxthub-better-auth-repro@049505f: prerender clears (build still fails later at the dummy-postgres migration — expected, unrelated)

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nuxt-better-auth-docs Ready Ready Preview, Comment Apr 17, 2026 7:51am

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 17, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@onmax/nuxt-better-auth@305

commit: b434757

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 17, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
better-auth b434757 Apr 17 2026, 07:52 AM

@onmax onmax merged commit f30fdde into main Apr 17, 2026
5 of 6 checks passed
@onmax onmax deleted the fix/nuxthub-prerender-db-import branch April 17, 2026 07:55
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