embed-prisma
raw JSON → 3.0.0 verified Fri May 01 auth: no javascript
Exposes Prisma's compiler API for NodeJS applications, enabling programmatic schema compilation, validation, TypeScript definition generation, and documentation/diagram creation without requiring the Prisma CLI. Current stable version is 3.0.0, released with a generator change from JS to TS. The library supports multiple schema files, discriminated result types (success, failure, exception), and integrates with Prisma v7. It is designed for Node.js only, not for browser environments, and is commonly used in AI-driven backend code generation pipelines.
Common errors
error Error: Cannot find module 'embed-prisma' ↓
cause Package not installed or wrong import path.
fix
Run 'npm install embed-prisma' and ensure import path is correct.
error SyntaxError: Named export 'EmbedPrisma' not found. The requested module 'embed-prisma' is a CommonJS module which may not support all module.exports as named exports. ↓
cause Using named import with require() or a bundler that misdetects module type.
fix
Use dynamic import: const { EmbedPrisma } = await import('embed-prisma');
error TypeError: prisma.compile is not a function ↓
cause EmbedPrisma not instantiated correctly, or wrong import.
fix
Ensure you import { EmbedPrisma } and instantiate: new EmbedPrisma()
error Error: Invalid schema file name. Keys must end with '.prisma' ↓
cause Passed object keys without .prisma extension.
fix
Use file names like 'schema.prisma' as keys.
Warnings
breaking v3.0.0 changed generator from JS to TS. Existing custom generators written in JS may need migration. ↓
fix Update custom Prisma generators to TypeScript, or use v2.x if JS is required.
breaking v2.0.0 bumped Prisma dependency to v7. Incompatible with older Prisma versions. ↓
fix Upgrade Prisma to v7 or newer; pin embed-prisma to v1.x if using Prisma <7.
deprecated CommonJS require() is deprecated since v3. The package is ESM-only. ↓
fix Use dynamic import: const { EmbedPrisma } = await import('embed-prisma');
gotcha The compile() method accepts an object with schema file names as keys; file names must include extension .prisma. ↓
fix Ensure keys end with '.prisma'.
gotcha Installation does not automatically include Prisma CLI dependencies; you must have a Prisma schema with a valid generator. ↓
fix Ensure your project has the required Prisma dependencies and generator block.
Install
npm install embed-prisma yarn add embed-prisma pnpm add embed-prisma Imports
- EmbedPrisma wrong
import EmbedPrisma from 'embed-prisma'correctimport { EmbedPrisma } from 'embed-prisma' - IEmbedPrismaResult wrong
const { IEmbedPrismaResult } = require('embed-prisma')correctimport { IEmbedPrismaResult } from 'embed-prisma' - EmbedPrisma wrong
const EmbedPrisma = require('embed-prisma')correctconst { EmbedPrisma } = await import('embed-prisma')
Quickstart
import { EmbedPrisma, IEmbedPrismaResult } from 'embed-prisma';
const prisma: EmbedPrisma = new EmbedPrisma();
const result: IEmbedPrismaResult = await prisma.compile({
"schema.prisma": `
datasource db {
provider = "sqlite"
url = "file:./dev.db"
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int @id @default(autoincrement())
name String
}
`
});
if (result.type === "success") {
console.log('Generated client at:', result.nodeModules);
console.log('Documentation:', result.document);
console.log('Diagrams:', result.diagrams);
} else if (result.type === "failure") {
console.error('Compile error:', result.reason);
} else if (result.type === "exception") {
console.error('Exception:', result.message);
}