{"id":20872,"library":"write-prettier-file","title":"write-prettier-file","description":"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.","status":"active","version":"3.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/fisker/write-prettier-file","tags":["javascript"],"install":[{"cmd":"npm install write-prettier-file","lang":"bash","label":"npm"},{"cmd":"yarn add write-prettier-file","lang":"bash","label":"yarn"},{"cmd":"pnpm add write-prettier-file","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"core formatting logic","package":"prettier-format","optional":false}],"imports":[{"note":"ESM-only since v3 (sync version removed). CommonJS require will fail.","wrong":"const writePrettierFile = require('write-prettier-file')","symbol":"default","correct":"import writePrettierFile from 'write-prettier-file'"},{"note":"Package exports a default export only, not a named export.","wrong":"import { writePrettierFile } from 'write-prettier-file'","symbol":"writePrettierFile","correct":"import writePrettierFile from 'write-prettier-file'"},{"note":"You can rename the default import to any name; no named exports exist.","wrong":"import { customName } from 'write-prettier-file'","symbol":"writePrettierFile as any name","correct":"import customName from 'write-prettier-file'"}],"quickstart":{"code":"import writePrettierFile from 'write-prettier-file'\n\n// Format and write a JavaScript file\nawait writePrettierFile('example.js', `const x = (a)=>a+1;`)\n\n// With options (override prettier config)\nawait writePrettierFile('style.css', 'body { color: red }', { singleQuote: true })\n\n// Disable config resolution\nawait writePrettierFile('file.js', 'let y=2', { resolveConfig: false })","lang":"typescript","description":"Shows basic usage: import, write with default formatting, options override, and config resolution disable."},"warnings":[{"fix":"Use await writePrettierFile(...) instead of writePrettierFile.sync(...).","message":"Sync version removed in v3.0.0. The function is now async-only and must be awaited.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use import writePrettierFile from 'write-prettier-file' (or const writePrettierFile = (await import('write-prettier-file')).default) in CommonJS via dynamic import.","message":"Import must be default import, not named. Attempting named import will yield undefined.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use async version or upgrade to v3 with await.","message":"The sync version (writePrettierFile.sync) existed in v2.x but is removed in v3. Using it in v2 is deprecated.","severity":"deprecated","affected_versions":"2.x"},{"fix":"Use new URL('file:///path') or pass a string path.","message":"File path can be string or URL object. Ensure URL is properly constructed.","severity":"gotcha","affected_versions":">=2.1.0"},{"fix":"Check prettier-format docs for supported options.","message":"Options are passed to prettier-format, not directly to Prettier. Some Prettier options might not be supported.","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":"Use async version: await writePrettierFile(...) or if needed v2.x.","cause":"Sync version was removed in v3.0.0.","error":"TypeError: writePrettierFile.sync is not a function"},{"fix":"Use dynamic import: const writePrettierFile = (await import('write-prettier-file')).default","cause":"ESM-only package imported in a CommonJS module.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Run npm install write-prettier-file, ensure package.json has it as dependency.","cause":"Package not installed or incorrect path.","error":"Error: Cannot find module 'write-prettier-file'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}