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
4 Replies
You've gone full bot mode! Let me fetch that AI answer for you ASAP.
The error
TypeError [ERR_INVALID_FILE_URL_PATH]: File URL must be absolute
is a known issue when using Prisma with ESM runtimes (like Nuxt/Nitro/Vite) and custom import setups. This typically happens because the generated Prisma Client or your wrapper tries to resolve paths using fileURLToPath(import.meta.url)
, but the value of import.meta.url
is not an absolute file URL in your build/runtime environment. This is especially problematic in serverless or edge-like environments, or when using custom output paths for the Prisma Client.
From the knowledge sources:
- This error is reproducible with Nuxt/Nitro and is caused by the way import.meta.url
is handled in those environments. The generated Prisma Client expects an absolute file URL, but tools like Nitro may provide something like file:///_entry.js
, which is not absolute and causes the error you see. The relevant code is in the generated client, where it tries to compute __dirname
using fileURLToPath(import.meta.url)
and fails if the URL is not absolute ESM Runtime: File URL path must be absolute with nuxt.
- There is currently no official workaround for this issue. The problem is with how the runtime and bundler handle module URLs and file resolution. Some users have tried to patch the generated client or adjust bundler settings, but there is no stable, documented solution from Prisma as of now.
- Using custom wrappers or dynamic imports (as in your prisma-wrapper
) does not resolve the underlying issue if the environment does not provide a proper absolute file URL.
What you can try:
- If possible, avoid custom wrappers and import the generated Prisma Client directly.
- Make sure you are not using the new ESM generator (provider = "prisma-client"
) unless you specifically need it; try switching to provider = "prisma-client-js"
as suggested by Prisma contributors [Prisma 6.6.0 TypeError: __banner_node_url](<https://github.com/prisma/prismaGitHub
GitHub - prisma/prisma: Next-generation ORM for Node.js & TypeScrip...
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB - prisma/prisma
/issues/26897>).
- If you are using Nuxt/Nitro/Vite, monitor the related GitHub issues for updates, as this is a known incompatibility.
Summary:
This is a known incompatibility between Prisma's generated client and certain ESM runtimes/build tools. There is no official fix yet, and the knowledge sources do not provide a reliable workaround. Consider using the default generator and direct imports, and follow the linked issues for updates. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
This is a known incompatibility between Prisma's generated client and certain ESM runtimes/build tools. There is no official fix yet, and the knowledge sources do not provide a reliable workaround. Consider using the default generator and direct imports, and follow the linked issues for updates. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Is this the same issue as described in this GH Discussion?
https://github.com/prisma/prisma/discussions/27138
GitHub
ERR_INVALID_ARG_VALUE with file:///_entry.js on Windows + Node 18/2...
Question ------------------------------------ I USE NUXT 3 -------------------------------------- prisma.ts import { PrismaClient } from './prisma-wrapper' export const prisma = globalThis....