Registry /
serialization / prettier-plugin-sql-cst
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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ import prettierPluginSqlCst from 'prettier-plugin-sql-cst'
✗ const prettierPluginSqlCst = require('prettier-plugin-sql-cst')
ESM-only since v0.19.3 – the package is compiled into a single ESM .js file. No default export actually exists; you use the package implicitly via Prettier's plugin resolution. Do not import directly.
sqlite
✓ // In .prettierrc: { "plugins": ["prettier-plugin-sql-cst"], "overrides": [{ "files": ["*.sql"], "options": { "parser": "sqlite" } }] }
✗ import { sqlite } from 'prettier-plugin-sql-cst'
sqlite is a parser name string, not an export. It is used as the parser option in Prettier configuration.
bigquery
✓ // In .prettierrc: { "plugins": ["prettier-plugin-sql-cst"], "overrides": [{ "files": ["*.sql"], "options": { "parser": "bigquery" } }] }
✗ import bigquery from 'prettier-plugin-sql-cst'
bigquery is a parser name string, not an export. Use in parser option.
Shows how to install the plugin, configure it in .prettierrc.json, and format a basic SQL query.
// Install dependencies
// npm install --save-dev prettier prettier-plugin-sql-cst
// Create a .prettierrc.json file:
{
"plugins": ["prettier-plugin-sql-cst"],
"overrides": [
{
"files": ["*.sql"],
"options": { "parser": "sqlite" }
}
]
}
// Then create a SQL file (e.g., test.sql):
SELECT a, b, c FROM tbl WHERE x > 10;
// Run prettier:
// npx prettier --write test.sql
// Output:
SELECT a, b, c
FROM tbl
WHERE x > 10;
prettier --version
Debug
Known issues
breakingv0.19.0+ - Upgraded sql-parser-cst to 0.39.0, possibly changing AST for some SQL constructs. Formatting may change.fixReview formatted output after upgrade. No manual fix available.
affects: >=0.19.0
breakingv0.17.0+ - PostgreSQL builtin data type names now formatted in upper case by default. sqlTypeCase, sqlIdentifierCase, sqlFunctionCase options added.fixAdd sqlTypeCase: 'lower' and sqlIdentifierCase: 'lower' to config for PostgreSQL if lowercase types are desired.
affects: >=0.17.0
breakingv0.19.3 - Package compiled into a single ESM .js file. Breaking for CommonJS consumers.fixEnsure project is ESM, or use a dynamic import: const prettierPluginSqlCst = await import('prettier-plugin-sql-cst'). Then use via Prettier's plugin system, not direct import. affects: >=0.19.3
gotcha`preserve` case option is incompatible with `sqlCanonicalSyntax: true` – added keywords like AS will always be uppercase.fixSet sqlCanonicalSyntax: false if preserving case is important, or accept uppercase keywords.
affects: <0.18.0? (present in release notes)
gotchaPostgreSQL, MySQL, MariaDB parsers are experimental – expect crashes on complex queries.fixUse sqlite or bigquery parsers for production; test with your SQL dialect thoroughly.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'prettier-plugin-sql-cst' require() of ES Module
The plugin is ESM-only since v0.19.3, but CommonJS require() is used.
fixUse import() or ensure your project is configured as ESM. Alternatively, downgrade to v0.19.2 or earlier. Or use Prettier's CLI which handles plugins internally.
TypeError: prettier-plugin-sql-cst.default is not a function
Direct import of the module and calling it as a function.
fixDo not import or call directly. Use the plugin via Prettier's plugin configuration in .prettierrc or CLI --plugin option.
Error: No parser could be inferred for file: myfile.sql
Prettier cannot auto-detect SQL dialect; no 'parser' option set.
fixSet parser in .prettierrc overrides or use --parser flag: prettier --plugin prettier-plugin-sql-cst --parser sqlite myfile.sql
Audit
Dependencies
prettierrequiredpeer dependency – the plugin requires Prettier to be installed