{"id":20321,"library":"prettier-format","title":"prettier-format","description":"Auto-loads Prettier config and formats code with a single async function. Current stable version is 4.0.0, released with breaking changes removing the default 'babel' parser and fixing the `filePath` option casing. Released on npm, maintained by fisker. Key differentiator: eliminates need to manually call `prettier.resolveConfig` and `prettier.format` separately; all configuration loading is done internally based on `filepath`.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/fisker/prettier-format","tags":["javascript"],"install":[{"cmd":"npm install prettier-format","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-format","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-format","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime peer dependency; this package formats code via Prettier's API.","package":"prettier","optional":false}],"imports":[{"note":"Package is ESM-only since v3, no CommonJS wrapper.","wrong":"const format = require('prettier-format')","symbol":"default","correct":"import format from 'prettier-format'"},{"note":"Default export only; named export does not exist.","wrong":"import { format } from 'prettier-format'","symbol":"format","correct":"import format from 'prettier-format'"},{"note":"Dynamic import yields a module object with only a default property.","wrong":"const { format } = await import('prettier-format')","symbol":"format","correct":"const format = (await import('prettier-format')).default"}],"quickstart":{"code":"import format from 'prettier-format';\n\n// Format with auto-loaded config from file path\nconst formatted = await format('const x = 1', {\n  filepath: '/path/to/file.js',\n  semi: false,\n});\nconsole.log(formatted);\n// 'const x = 1\\n'","lang":"javascript","description":"Demonstrates using the default export to format source code with automatic config loading based on filepath."},"warnings":[{"fix":"Always provide 'filepath' option (or explicit 'parser') when calling format().","message":"Default parser 'babel' removed in v4.0.0; must pass 'parser' or 'filepath' option.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Replace 'filePath' with 'filepath' in options object.","message":"Option 'filePath' (camelCase) no longer works; use 'filepath' (lowercase) instead.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Upgrade Prettier to version 3 or later.","message":"Support for Prettier <3 dropped; requires Prettier 3.x.","severity":"deprecated","affected_versions":">=3.2.0"},{"fix":"Use import or dynamic import instead of require().","message":"Module is ESM-only since v3; cannot be require()'d.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Switch to import statement or use dynamic import: const format = (await import('prettier-format')).default","cause":"Using CommonJS require() on an ESM-only package.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported."},{"fix":"Use import format from 'prettier-format' (default import).","cause":"Default import not used; attempting to use named import or destructuring incorrectly.","error":"TypeError: format is not a function"},{"fix":"Provide a 'filepath' option or an explicit 'parser' option like 'babel'.","cause":"Calling format() without filepath or parser option (breaking change in v4).","error":"Error: No parser and no filepath given, cannot infer parser."},{"fix":"Replace 'filePath' with 'filepath' in options.","cause":"Using camelCase 'filePath' instead of lowercase 'filepath'.","error":"Warning: 'filePath' option is deprecated. Use 'filepath' instead."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}