Registry / devops / prettier-plugin-powershell

prettier-plugin-powershell

JSON →
library2.1.0jsnpmunverified

Prettier plugin (v2.1.0, monthly releases) for formatting PowerShell source files (.ps1, .psm1, .psd1) with idiomatic defaults. Supports fine-grained configuration like indentation style/width, trailing commas, brace style, alias rewriting, and keyword casing. Requires Node.js >=20.11.0, Prettier >=3, and has an optional peer dependency on TypeScript ^6.0.3 for types. Extensively tested with ≥95% coverage, ready for CI/CD pipelines. Differentiator: first-class Prettier integration with options beyond basic PowerShell formatters.

npm install prettier-plugin-powershell
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-PO
P
prettier-plugin-powershell
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.

default
import plugin from 'prettier-plugin-powershell'
const plugin = require('prettier-plugin-powershell')
ESM-only since v2. CommonJS require will fail.
powershell
import { powershell } from 'prettier-plugin-powershell'
import { powershell } from 'prettier'
Named export for the AST parser; use when you need direct access to the parser object.
Plugin
import type { Plugin } from 'prettier-plugin-powershell'
import { Plugin } from 'prettier-plugin-powershell'
Type import for TypeScript users. Plugin interface is not a value export.

Formats a simple PowerShell script using the plugin programmatically with custom options.

import prettier from 'prettier'; import plugin from 'prettier-plugin-powershell'; const source = `$greeting = "Hello, World!" Write-Output $greeting `; const formatted = await prettier.format(source, { filepath: 'script.ps1', parser: 'powershell', plugins: [plugin], tabWidth: 4, powershellTrailingComma: 'all', }); console.log(formatted);
Debug
Known issues
breakingPlugin is ESM-only since v2.0.0. CommonJS require() will throw.
fix
Use ESM import or dynamic import().
affects: >=2.0.0
breakingNode.js >=20.11.0 required since v2.0.0.
fix
Upgrade Node.js to 20.11.0 or higher.
affects: >=2.0.0
breakingPrettier v3 or higher required since v2.0.0.
fix
Upgrade Prettier to v3+.
affects: >=2.0.0
deprecatedOption powershellRewritAliases (note: missing 'e') removed in v2.0.0; use powershellRewriteAliases (correct spelling).
fix
Rename option to powershellRewriteAliases.
affects: >=2.0.0
gotchaPlugin must be listed in Prettier config's `plugins` array AND parser must be set to 'powershell'.
fix
Set both 'plugins: ["prettier-plugin-powershell"]' and 'parser: "powershell"' .
affects: >=1.0.0
gotchaFormatting multi-line strings and here-strings may differ from native PowerShell expectations; always verify output.
fix
Use powershellIndentHereStrings option to control indent behavior.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'prettier-plugin-powershell' imported from...
Missing plugin in package.json dependencies or incorrect import path.
fix
Run `npm install --save-dev prettier-plugin-powershell` and verify the package is in node_modules.
TypeError: Cannot read properties of undefined (reading 'powershell')
Parser not set to 'powershell' when using plugin.
fix
Add 'parser: "powershell"' to Prettier options or config file.
SyntaxError: Unexpected token 'export'
Using CommonJS require() with ESM-only package.
fix
Switch to ESM import (import ... from ...) or use dynamic import().
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
prettierrequiredpeer dependency: required to run the plugin
typescriptoptionaloptional peer dependency: provides type definitions for custom AST work
Agent activity
4 hits · last 30 days
node
4
Resources
prettier-plugin-powershell — npm install prettier-plugin-powershell · libregistry