Registry / devops / write-prettier-file

write-prettier-file

JSON →
library3.0.3jsnpmunverified

A small utility that writes a file after formatting the content with Prettier. The package simplifies the workflow of formatting code before saving it to disk. Current stable version is 3.0.3 (as of 2025). Release cadence is irregular with minor updates. Key differentiators: it integrates formatting and file writing into one call, supports prettier config resolution, and works with string or URL file paths. Breaking change in v3.0.0 removed the sync version, making it async-only. Requires Node.js >=16.

npm install write-prettier-file
INSTALL
IMPORT
SIG · WRITE-PRETTIER-FIL
W
write-prettier-file
devopsjavascriptv3.0.3
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

default
import writePrettierFile from 'write-prettier-file'
const writePrettierFile = require('write-prettier-file')
ESM-only since v3 (sync version removed). CommonJS require will fail.
writePrettierFile
import writePrettierFile from 'write-prettier-file'
import { writePrettierFile } from 'write-prettier-file'
Package exports a default export only, not a named export.
writePrettierFile as any name
import customName from 'write-prettier-file'
import { customName } from 'write-prettier-file'
You can rename the default import to any name; no named exports exist.

Shows basic usage: import, write with default formatting, options override, and config resolution disable.

import writePrettierFile from 'write-prettier-file' // Format and write a JavaScript file await writePrettierFile('example.js', `const x = (a)=>a+1;`) // With options (override prettier config) await writePrettierFile('style.css', 'body { color: red }', { singleQuote: true }) // Disable config resolution await writePrettierFile('file.js', 'let y=2', { resolveConfig: false })
Debug
Known issues
breakingSync version removed in v3.0.0. The function is now async-only and must be awaited.
fix
Use await writePrettierFile(...) instead of writePrettierFile.sync(...).
affects: >=3.0.0
gotchaImport must be default import, not named. Attempting named import will yield undefined.
fix
Use import writePrettierFile from 'write-prettier-file' (or const writePrettierFile = (await import('write-prettier-file')).default) in CommonJS via dynamic import.
affects: >=1.0.0
deprecatedThe sync version (writePrettierFile.sync) existed in v2.x but is removed in v3. Using it in v2 is deprecated.
fix
Use async version or upgrade to v3 with await.
affects: 2.x
gotchaFile path can be string or URL object. Ensure URL is properly constructed.
fix
Use new URL('file:///path') or pass a string path.
affects: >=2.1.0
gotchaOptions are passed to prettier-format, not directly to Prettier. Some Prettier options might not be supported.
fix
Check prettier-format docs for supported options.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: writePrettierFile.sync is not a function
Sync version was removed in v3.0.0.
fix
Use async version: await writePrettierFile(...) or if needed v2.x.
SyntaxError: Cannot use import statement outside a module
ESM-only package imported in a CommonJS module.
fix
Use dynamic import: const writePrettierFile = (await import('write-prettier-file')).default
Error: Cannot find module 'write-prettier-file'
Package not installed or incorrect path.
fix
Run npm install write-prettier-file, ensure package.json has it as dependency.
Upgrade
Version history
3.0.3latest on npm
Audit
Dependencies
prettier-formatrequiredcore formatting logic
Agent activity
12 hits · last 30 days
node
10
Amazon
1
Resources
write-prettier-file — npm install write-prettier-file · libregistry