Registry / devops / prettier-hbs

prettier-hbs

JSON →
library3.1.7jsnpmunverified

A fork of Prettier (v2.8.8 base) that patches Handlebars formatting. Fixes conditional attribute blocks, one-line blocks, partial syntax, trailing slash in self-closing tags, and forces single quotes in expressions. Current version 3.1.7 supports Node >=14, ships TypeScript types, and is exclusively ESM. Unlike the official Prettier, this fork targets Handlebars projects that need specific HBS formatting fixes not accepted upstream. Release cadence is irregular; last update June 2023.

npm install prettier-hbs
INSTALL
IMPORT
SIG · PRETTIER-HBS
P
prettier-hbs
devopsjavascriptv3.1.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

format
✓ import { format } from 'prettier-hbs'
✗ const { format } = require('prettier-hbs')
ESM-only since v3. CommonJS require will fail.
resolveConfig
✓ import { resolveConfig } from 'prettier-hbs'
Used to load .prettierrc configuration programmatically.
default (named export)
✓ import prettier from 'prettier-hbs'
✗ import * as prettier from 'prettier-hbs'
Default export is the same as the module namespace. Named exports are also available.
config options (TypeScript)
✓ import type { Options } from 'prettier-hbs'
✗ import { Options } from 'prettier-hbs'
Options type is only available as a type import in TypeScript.

Formats a Handlebars template using the glimmer parser with single quotes option. Uses ESM import syntax.

import { format } from 'prettier-hbs'; const hbsCode = `<div> {{#if condition}} <span>{{name}}</span> {{/if}} </div>`; const formatted = await format(hbsCode, { parser: 'glimmer', singleQuote: true }); console.log(formatted); // Output: // <div> // {{#if condition}} // <span>{{name}}</span> // {{/if}} // </div>
Debug
Known issues
breakingprettier-hbs v3 is ESM-only and no longer supports CommonJS (require()).
fix
Switch to ESM imports (import ... from 'prettier-hbs') or use dynamic import().
affects: >=3.0.0
deprecatedThe 'parser' option must be set to 'glimmer' for Handlebars files. Using the default 'babel' or 'html' parser will produce incorrect output.
fix
Configure prettier-hbs overrides in your .prettierrc: { "overrides": [{ "files": "*.hbs", "options": { "parser": "glimmer" } }] }
affects: *
gotchaprettier-hbs is a fork based on Prettier v2.8.8. Options and behavior from later Prettier versions (e.g., v3) are not available.
fix
Refer to Prettier v2 documentation for supported options. Do not expect Prettier v3 features.
affects: *
gotchaThe package forces single quotes in Handlebars expressions (e.g., {{t 'something'}}) regardless of the singleQuote option for other languages.
fix
If you need double quotes in expressions, this fork may not suit your project. Consider upstream Prettier or another tool.
affects: *
gotchaTrailing newline at end of file is always forced to a single \n, not configurable.
fix
If you need no trailing newline or multiple newlines, post-process the output.
affects: *
Errors
Common errors & fixes
Cannot find module 'prettier-hbs'
Package not installed or wrong import syntax.
fix
Run `npm install prettier-hbs` and use ESM import: `import { format } from 'prettier-hbs';`
SyntaxError: Unexpected token 'export'
Using CommonJS require() with an ESM-only package (v3+).
fix
Switch to ESM: set `"type": "module"` in package.json or use dynamic import: `const prettier = await import('prettier-hbs');`
TypeError: prettier.format is not a function
Default import used incorrectly; format is a named export.
fix
Use named import: `import { format } from 'prettier-hbs';`
Error: No parser could be inferred for file
No parser specified in config or override for .hbs files.
fix
Add to .prettierrc: `{ "overrides": [{ "files": "*.hbs", "options": { "parser": "glimmer" } }] }`
Upgrade
Version history
3.1.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
Bingbot
15
node
2
Resources
prettier-hbs — npm install prettier-hbs · libregistry