diff --git a/packages/cli/src/utils/exec-utils.ts b/packages/cli/src/utils/exec-utils.ts index 2ef0e26d..0e4ad3ed 100644 --- a/packages/cli/src/utils/exec-utils.ts +++ b/packages/cli/src/utils/exec-utils.ts @@ -30,13 +30,24 @@ export function execPackage( * Utility for running prisma commands */ export function execPrisma(args: string, options?: Omit & { env?: Record }) { - let prismaPath: string; - if (typeof import.meta.resolve === 'function') { - // esm - prismaPath = fileURLToPath(import.meta.resolve('prisma/build/index.js')); - } else { - // cjs - prismaPath = require.resolve('prisma/build/index.js'); + let prismaPath: string | undefined; + try { + if (typeof import.meta.resolve === 'function') { + // esm + prismaPath = fileURLToPath(import.meta.resolve('prisma/build/index.js')); + } else { + // cjs + prismaPath = require.resolve('prisma/build/index.js'); + } + } catch { + // ignore and fallback } + + if (!prismaPath) { + // fallback to npx/bunx execute + execPackage(`prisma ${args}`, options); + return; + } + execSync(`node ${prismaPath} ${args}`, options); }