{"id":20409,"library":"prettier-plugin-razor","title":"Prettier Razor Plugin","description":"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.","status":"active","version":"1.0.11-alpha.1","language":"javascript","source_language":"en","source_url":"https://github.com/KristinaPlusPlus/prettier-plugin-razor","tags":["javascript","prettier","razor","plugin"],"install":[{"cmd":"npm install prettier-plugin-razor","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-razor","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-razor","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency as a Prettier plugin","package":"prettier","optional":false}],"imports":[{"note":"Not imported directly; configured in Prettier config.","wrong":"const plugin = require('prettier-plugin-razor')","symbol":"default","correct":"module.exports = { plugins: ['prettier-plugin-razor'] }"},{"note":"Used as a plugin string, not a default import.","wrong":"import razor from 'prettier-plugin-razor'","symbol":"Default","correct":"import { prettier-plugin-razor } from 'prettier-plugin-razor'"},{"note":"Plugin is specified in options, not required directly.","wrong":"const razor = require('prettier-plugin-razor')","symbol":"require","correct":"const prettier = require('prettier'); prettier.format(code, { parser: 'razor', plugins: ['prettier-plugin-razor'] })"}],"quickstart":{"code":"// .prettierrc\n{\n  \"plugins\": [\"prettier-plugin-razor\"],\n  \"overrides\": [{\n    \"files\": \"*.cshtml\",\n    \"options\": {\n      \"parser\": \"razor\"\n    }\n  }]\n}\n\n// Install\n// npm install --save-dev prettier prettier-plugin-razor","lang":"javascript","description":"Configure Prettier to use the Razor plugin for .cshtml files."},"warnings":[{"fix":"Pin to exact version in package.json.","message":"Plugin is in alpha; breaking changes may occur between minor versions.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use Prettier CLI or API directly.","message":"Only supports standalone Prettier, not integrations like ESLint or stylelint.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Check formatting output and raise issues on GitHub.","message":"Does not support all Razor constructs; complex nesting may be misformatted.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install --save-dev prettier-plugin-razor","cause":"Plugin not installed or not listed in Prettier plugins.","error":"Cannot find module 'prettier-plugin-razor'"},{"fix":"Add 'parser: \"razor\"' to Prettier configuration.","cause":"Plugin not loaded or parser not specified in options.","error":"Couldn't resolve parser \"razor\""}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}