Registry / devops / prettier-plugin-jinja-template

prettier-plugin-jinja-template

JSON →
library2.1.0jsnpmunverified

Prettier plugin for formatting Jinja (Jinja2) template files in HTML and other file types. Current stable version is 2.1.0. It runs as a Prettier plugin and requires Prettier v3+. It parses Jinja syntax mixed with HTML, respects Jinja block structure, and supports range ignores via HTML or Jinja comments. Key differentiators: dedicated Jinja parser (not a generic Liquid/Nunjucks plugin), supports Jinja's specific control flow (for, if, block, etc.), and is actively maintained. It does not format plain HTML or CSS/JS within templates unless paired with a second Prettier plugin like @prettier/plugin-html or prettier-plugin-go-template. TypeScript types are shipped.

npm install prettier-plugin-jinja-template
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-JI
P
prettier-plugin-jinja-template
devopsjavascriptv2.1.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.

plugin (via Prettier config)
Use .prettierrc: { "plugins": ["prettier-plugin-jinja-template"] }
Trying to import the plugin programmatically with require() or import, which is not supported—the plugin must be loaded via Prettier config or CLI --plugin flag.
ESM and CJS both work via Prettier config; no direct JavaScript import of the plugin exists.
Parser (jinja-template)
npx prettier --parser=jinja-template --write file.html
npx prettier --parser=jinja --write file.html -- wrong parser name, must be exactly 'jinja-template'
The parser name is 'jinja-template', not 'jinja' or 'jinja2'.
Override (prettier config)
{ "overrides": [{ "files": "*.html", "options": { "parser": "jinja-template" } }] }
Setting parser: 'jinja-template' globally in .prettierrc without override, which will break formatting of non-Jinja files.
Use overrides to apply only to files containing Jinja templates; otherwise Prettier will fail to parse pure HTML/JS/CSS files.

Installs Prettier and the plugin, configures .prettierrc with the Jinja parser override, creates a sample template, and formats it.

npm install --save-dev prettier prettier-plugin-jinja-template echo '{ "plugins": ["prettier-plugin-jinja-template"], "overrides": [{ "files": "*.html", "options": { "parser": "jinja-template" } }] }' > .prettierrc echo '<!DOCTYPE html> <html> <head> <title>{% if title %}{{ title }}{% else %}Default{% endif %}</title> </head> <body> <ul> {% for item in items %} <li>{{ item.name }}</li> {% endfor %} </ul> </body> </html>' > template.html npx prettier --write template.html
Debug
Known issues
breakingDropped support for Node.js 14 and 16 in v2.0.0
fix
Upgrade to Node.js 18 or later.
affects: >=2.0.0
breakingRemoved quoteAttributes option in v2.0.0
fix
Remove any usage of quoteAttributes from .prettierrc; the option is no longer available.
affects: >=2.0.0
gotchaThe plugin only formats Jinja syntax; it does not format HTML, CSS, or JavaScript within templates. Use additional plugins like @prettier/plugin-html or prettier-plugin-go-template for full HTML formatting.
fix
Chain multiple Prettier plugins or consider using prettier-plugin-go-template which handles HTML+Jinja together.
affects: >=1.0.0
deprecatedUsing --stdin-filepath with the plugin may not work correctly in some versions; always specify the file path.
fix
Use explicit file paths with the plugin: npx prettier --plugin=prettier-plugin-jinja-template --parser=jinja-template --write file.html
affects: >=1.0.0
Errors
Common errors & fixes
[error] Cannot find module 'prettier-plugin-jinja-template'
The plugin is not installed or not in node_modules.
fix
Run 'npm install --save-dev prettier prettier-plugin-jinja-template' and ensure the working directory contains the project root.
[error] No parser could be inferred for file template.html
The parser is not set via override or --parser flag. Prettier defaults to HTML parser.
fix
Add 'parser: "jinja-template"' to .prettierrc overrides for *.html files, or use npx prettier --parser=jinja-template --write template.html
Error: Invalid option name: quoteAttributes
Option was removed in v2.0.0 but still present in config.
fix
Remove 'quoteAttributes' from .prettierrc or upgrade config to remove it.
TypeError: Cannot read properties of undefined (reading 'source')
This can occur when the plugin encounters a malformed Jinja expression or unexpected syntax, especially with empty expressions.
fix
Check Jinja syntax for errors, ensure all {% %} blocks are properly closed, and update to latest version.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
prettierrequiredRuntime peer dependency; the plugin is loaded by Prettier and requires version ^3.0.0
Agent activity
2 hits · last 30 days
node
2
Resources
prettier-plugin-jinja-template — npm install prettier-plugin-jinja-template · libregistry