fix(mongoose): fall back to process.env when run outside Nitro
Some checks failed
Test / vitest (push) Successful in 11m8s
Test / playwright (push) Failing after 6m57s
Test / visual (push) Failing after 6m47s
Test / Notify on failure (push) Successful in 2s

connectDB() called useRuntimeConfig() unconditionally — works inside
the Nuxt/Nitro runtime but throws ReferenceError for standalone Node
scripts (seed-members.js, seed-tags.js, etc.). CI exposed this when
trying to run seed-all.js. Detect the auto-import and fall back to
process.env when it's not available; preserves Nitro behavior.
This commit is contained in:
Jennie Robinson Faber 2026-05-01 10:46:47 +01:00
parent f66189cfd6
commit 6bfb078e45

View file

@ -7,7 +7,10 @@ export const connectDB = async () => {
return;
}
const MONGODB_URI = useRuntimeConfig().mongodbUri;
const MONGODB_URI =
typeof useRuntimeConfig === 'function'
? useRuntimeConfig().mongodbUri
: process.env.NUXT_MONGODB_URI || process.env.MONGODB_URI;
try {
await mongoose.connect(MONGODB_URI, {