prettier-plugin-erb
raw JSON → 0.4.0 verified Sat Apr 25 auth: no javascript
A Prettier plugin for formatting .html.erb files, currently at version 0.4.0. It integrates with Prettier (>=2.0.0 <2.3) and depends on @prettier/plugin-ruby for formatting multiline Ruby expressions. Key differentiators: allows ERB formatting within Prettier's ecosystem, supports single-line expressions, and includes basic comment handling. The plugin is relatively new with limited features (no block expression formatting yet) and may have bugs; users are encouraged to ignore problematic files via .prettierignore.
Common errors
error SyntaxError: Unexpected token '>' ↓
cause Prettier version >=2.3 is incompatible with this plugin.
fix
Downgrade Prettier to version 2.2.x or lower.
error Error: Cannot find module '@prettier/plugin-ruby' ↓
cause Missing peer dependency @prettier/plugin-ruby.
fix
Install the missing peer:
yarn add -D @prettier/plugin-ruby error Error: [object Object] ↓
cause Bug in older versions (<0.4.0) when formatting certain ERB expressions.
fix
Upgrade to version 0.4.0 or later.
error Cannot read property 'type' of undefined ↓
cause Block expressions (e.g., <% if %>) not supported; the plugin cannot parse them.
fix
Remove or rewrite block expressions as single-line ERB, or add file to .prettierignore.
Warnings
breaking The plugin requires Prettier <2.3 due to compatibility issues with Prettier options. ↓
fix Use Prettier version 2.2.x or lower. Check peerDependencies: prettier >=2.0.0 <2.3.
gotcha Block expressions (e.g., <% if … %> … <% end %>) are not formatted; only single-line expressions work. ↓
fix Upgrade to v0.2.0+ for single-line expressions; block expressions still not supported in any version.
gotcha The plugin may return `[object Object]` as output in edge cases (fixed in v0.4.0). ↓
fix Upgrade to v0.4.0 or later.
deprecated The `print` function replaces `embed` for error logging (v0.2.0+). ↓
fix Upgrade to v0.2.0+ if you rely on error formatting.
gotcha The plugin may format files incorrectly; add problematic files to .prettierignore. ↓
fix Use .prettierignore to exclude files that cause errors or unwanted formatting.
Install
npm install prettier-plugin-erb yarn add prettier-plugin-erb pnpm add prettier-plugin-erb Imports
- prettier-plugin-erb wrong
Using `require('prettier-plugin-erb')` in codecorrectAdd to .prettierrc: { "plugins": ["prettier-plugin-erb"] } - default wrong
Importing as `import erb from 'prettier-plugin-erb'`correctNot applicable; no programmatic export. - N/A wrong
Using `@prettier/plugin-ruby` instead of `prettier-plugin-erb` for ERB filescorrectNot applicable
Quickstart
// Install dependencies
// yarn add -D prettier@2.2.0 @prettier/plugin-ruby@1.0.0 prettier-plugin-erb@0.4.0
// .prettierrc
{
"plugins": [
"@prettier/plugin-ruby",
"prettier-plugin-erb"
],
"tabWidth": 2
}
// Run
// npx prettier --write app/views/**/*.html.erb