Nguyễn Khôi
PPrisma
•Created by Nguyễn Khôi on 5/10/2025 in #help-and-questions
ReferenceError: __dirname is not defined in ES module scope
prisma.ts
import { PrismaClient } from '../../generated/prisma'
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined
}
const prisma =
globalForPrisma.prisma ??
new PrismaClient({
log: ['query', 'error', 'warn'],
})
if (process.env.NODEENV !== 'production') globalForPrisma.prisma = prisma
export default prisma;
visual code
C:\Users\nguye\Desktop\project6>node .output/server/index.mjs
file:///C:/Users/nguye/Desktop/project6/.output/server/chunks//nitro.mjs:6266
M.default.join(dirname, "../query-engine-darwin");
^
ReferenceError: dirname is not defined in ES module scope
at file:///C:/Users/nguye/Desktop/project6/.output/server/chunks/_/nitro.mjs:6266:16
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:106:12)
Node.js v18.20.8
6 replies
PPrisma
•Created by Nguyễn Khôi on 5/10/2025 in #help-and-questions
TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
In the prisma file, I put
import { PrismaClient } from './prisma-wrapper'
const prisma = globalThis.prisma || new PrismaClient()
if (process.env.NODE_ENV !== 'production') globalThis.prisma = prisma
export default prisma;
in prisma-wrapper
import type { PrismaClient as ImportedPrismaClient } from "../../generated/prisma"
import { createRequire } from 'node:module'
import { fileURLToPath } from 'node:url'
const require = createRequire(fileURLToPath(import.meta.url))
const { PrismaClient: RequiredPrismaClient } = require("../../generated/prisma")
const _PrismaClient = RequiredPrismaClient as typeof ImportedPrismaClient
export class PrismaClient extends _PrismaClient {}
in vs code when I run "npm run preview"
node:internal/errors:496
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_FILE_URLPATH]: File URL must be absolute
at new NodeError (node:internal/errors:405:5)
at getPathFromURLWin32 (node:internal/url:1450:11)
at fileURLToPath (node:internal/url:1480:22)
at file:///C:/Users/ngguye/Desktop/project6/.output/server/chunks//nitro.mjs:5438:31
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:106:12) {
code: 'ERR_INVALID_FILE_URL_PATH'
}
Node.js v18.20.8
6 replies