Registry / web-framework / prettier-plugin-razor

prettier-plugin-razor

JSON →
library1.0.11-alpha.1jsnpmunverified

Prettier plugin for formatting Razor (.cshtml) files used in ASP.NET Core MVC and Blazor. Current stable version is 1.0.11-alpha.1. Released irregularly as alpha. Key differentiator: brings consistent code formatting to Razor templates within the Prettier ecosystem, supporting directives like @code, @functions, and HTML/CSS/C# code segments. Alternatives include built-in Visual Studio formatters, but this plugin integrates with Prettier workflows and CI pipelines.

npm install prettier-plugin-razor
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-RA
P
prettier-plugin-razor
web-frameworkjavascriptv1.0.11-alpha.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

default
✓ module.exports = { plugins: ['prettier-plugin-razor'] }
✗ const plugin = require('prettier-plugin-razor')
Not imported directly; configured in Prettier config.
Default
✓ import { prettier-plugin-razor } from 'prettier-plugin-razor'
✗ import razor from 'prettier-plugin-razor'
Used as a plugin string, not a default import.
require
✓ const prettier = require('prettier'); prettier.format(code, { parser: 'razor', plugins: ['prettier-plugin-razor'] })
✗ const razor = require('prettier-plugin-razor')
Plugin is specified in options, not required directly.

Configure Prettier to use the Razor plugin for .cshtml files.

// .prettierrc { "plugins": ["prettier-plugin-razor"], "overrides": [{ "files": "*.cshtml", "options": { "parser": "razor" } }] } // Install // npm install --save-dev prettier prettier-plugin-razor
Debug
Known issues
gotchaPlugin is in alpha; breaking changes may occur between minor versions.
fix
Pin to exact version in package.json.
affects: >=1.0.0
gotchaOnly supports standalone Prettier, not integrations like ESLint or stylelint.
fix
Use Prettier CLI or API directly.
affects: >=1.0.0
gotchaDoes not support all Razor constructs; complex nesting may be misformatted.
fix
Check formatting output and raise issues on GitHub.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-razor'
Plugin not installed or not listed in Prettier plugins.
fix
npm install --save-dev prettier-plugin-razor
Couldn't resolve parser "razor"
Plugin not loaded or parser not specified in options.
fix
Add 'parser: "razor"' to Prettier configuration.
Upgrade
Version history
1.0.11-alpha.1latest on npm
Audit
Dependencies
prettierrequiredpeer dependency as a Prettier plugin
Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
prettier-plugin-razor — npm install prettier-plugin-razor · libregistry