Registry / serialization / prettier-plugin-sql

prettier-plugin-sql

JSON →
library0.20.0jsnpmunverified

Prettier plugin for formatting SQL files and SQL-in-JS. Wraps sql-formatter and node-sql-parser to support 20+ dialects including BigQuery, PostgreSQL, MySQL, ClickHouse. Requires Prettier 3.0.3+ and Node 14.18+. Version 0.20.0 adds ClickHouse support. Plugin is under active development but stable for basic usage. Differentiator: integrates with prettier-plugin-embed for embedded SQL in tagged templates.

npm install prettier-plugin-sql
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-SQ
P
prettier-plugin-sql
serializationjavascriptv0.20.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

prettier-plugin-sql
Prettier plugin loaded via plugins config in .prettierrc: { "plugins": ["prettier-plugin-sql"] }
import prettierPluginSql from 'prettier-plugin-sql'
Not imported directly; Prettier discovers it when listed in plugins array.
SqlBaseOptions
import type { SqlBaseOptions } from 'prettier-plugin-sql'
const { SqlBaseOptions } = require('prettier-plugin-sql')
Type only; erased at runtime. In CJS, use import() or require with .d.ts.
PrettierPluginEmbedOptions
import type { PrettierPluginEmbedOptions } from 'prettier-plugin-embed'
For SQL-in-JS formatting, embed options come from a separate package.

Basic setup: add plugin to .prettierrc, configure PostgreSQL dialect and uppercase keywords, format a SQL file.

// Install: npm i -D prettier prettier-plugin-sql // .prettierrc { "plugins": ["prettier-plugin-sql"], "language": "postgresql", "keywordCase": "upper" } // Run: npx prettier --write db.sql // Before (db.sql): // sELect first_name, species froM // animals // WhERE // id = 1 // // After: // SELECT // first_name, // species // FROM // animals // WHERE // id = 1
prettier --version
Debug
Known issues
breakingprettier-plugin-sql requires Prettier v3.0.3 or later
fix
Upgrade Prettier to ^3.0.3
affects: <3.0.3
deprecatedCommonJS named exports removed in v0.19.2; use default export for CJS
fix
Use require('prettier-plugin-sql').default or switch to ESM
affects: >=0.19.2
gotchaOptions like params, paramTypes, dialect must be JSON-stringified strings (JSOX). Passing objects will silently fail.
fix
Set params: JSON.stringify({}) instead of params: {}
affects: >=0.0.0
gotchaWhen using node-sql-parser formatter, only a subset of sql-formatter options are available; language defaults to 'sql'.
fix
Set formatter: 'sql-formatter' for full option support.
affects: >=0.0.0
deprecatedNode.js v14 is EOL; future releases may drop support
fix
Upgrade to Node.js 16 or higher.
affects: >=0.18.0
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-sql'
Plugin not installed or not in node_modules
fix
Run: npm install -D prettier prettier-plugin-sql
Error: Could not load plugin 'prettier-plugin-sql'
Prettier version <3.0.3
fix
Upgrade Prettier: npm install -D prettier@latest
Module not found: Can't resolve 'prettier-plugin-sql'
Importing directly instead of using Prettier plugin system
fix
Do not import; add to .prettierrc plugins array.
TypeError: Cannot read properties of undefined (reading 'format')
Using node-sql-parser with unsupported language/dialect
fix
Use formatter: 'sql-formatter' or ensure language is supported by node-sql-parser.
Upgrade
Version history
0.20.0latest on npm
Audit
Dependencies
prettierrequiredpeer dependency (^3.0.3) required at runtime
Agent activity
8 hits · last 30 days
node
8
Resources
prettier-plugin-sql — npm install prettier-plugin-sql · libregistry