prettier-plugin-prisma

raw JSON →
5.0.0 verified Sat Apr 25 auth: no javascript

Prettier plugin for formatting Prisma schema files (.prisma). Current stable version is 5.0.0, released Dec 2023. It uses the official Prisma schema formatter WASM binary (@prisma/prisma-schema-wasm) to ensure formatting matches Prisma CLI output. The plugin auto-detects .prisma files and integrates seamlessly with Prettier. It requires Prettier >=2 or >=3 and Node >=14. Active development tracks Prisma releases closely, with frequent bumps to the underlying Prisma formatting engine.

error Cannot find module 'prettier-plugin-prisma'
cause Plugin not installed or Prettier cannot locate it.
fix
Run npm install -D prettier-plugin-prisma and ensure it's listed in package.json devDependencies.
error Error: No plugin detected for "*.prisma" files.
cause Prettier is not configured to use the plugin.
fix
Add "plugins": ["prettier-plugin-prisma"] to your .prettierrc file.
error TypeError: prettierPluginPrisma.default is not a function
cause Using CommonJS require incorrectly when plugin exports a single default object.
fix
Use const prettierPluginPrisma = require('prettier-plugin-prisma'); without .default.
error Prettier failed to load plugin due to WebAssembly.instantiateStreaming
cause WASM binary failed to load, possibly due to Content Security Policy or unsupported Node version.
fix
Ensure Node.js >=14 and no CSP blocking WASM. Use --no-wasm or upgrade Node.js.
breaking v5.0.0 migrated from @prisma/prisma-fmt-wasm to @prisma/prisma-schema-wasm. The formatting output may differ slightly from previous versions.
fix Review and commit any formatting changes after upgrading. No code changes required.
gotcha Plugin only formats .prisma files; it does not lint or validate Prisma schema syntax.
fix Use Prisma CLI (`prisma validate`) for schema validation.
gotcha The plugin relies on a WASM binary; may not work in all restricted environments (e.g., some serverless platforms) without Node.js WASM support.
fix Ensure Node.js version supports WASM (>=14). If issues persist, report to the plugin's GitHub issues.
deprecated v4.x and earlier used @prisma/prisma-fmt-wasm. That dependency is deprecated in v5.
fix Upgrade to v5.0.0 or later to use the new WASM package.
gotcha Installing the plugin globally may not work; prefer local install in project devDependencies.
fix Run `npm i -D prettier-plugin-prisma` inside your project.
npm install prettier-plugin-prisma
yarn add prettier-plugin-prisma
pnpm add prettier-plugin-prisma

Demonstrates installing the plugin, configuring Prettier to use it, and formatting a .prisma schema file.

// 1. Install
npm i -D prettier prettier-plugin-prisma

// 2. In .prettierrc (JSON or YAML)
{
  "plugins": ["prettier-plugin-prisma"],
  "tabWidth": 2,
  "printWidth": 100
}

// 3. Create a Prisma file: schema.prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  posts     Post[]
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model Post {
  id        Int      @id @default(autoincrement())
  title     String
  content   String?
  author    User     @relation(fields: [authorId], references: [id])
  authorId  Int
  createdAt DateTime @default(now())
}

// 4. Run Prettier
npx prettier --write schema.prisma