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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ import prettier from 'prettier';
✗ const prettier = require('prettier');
Prettier is ESM-only since v3; use dynamic import or ES module syntax.
plugin
✓ import * as prettierPluginApex from 'prettier-plugin-apex';
✗ const prettierPluginApex = require('prettier-plugin-apex');
Plugin is ESM-only; use ES import syntax.
Options
✓ import type { Options } from 'prettier';
✗ import { Options } from 'prettier-plugin-apex';
Plugin does not export its own types; use Prettier's Options type.
Formats a simple Apex class using Prettier with the Apex plugin.
import prettier from 'prettier';
import * as prettierPluginApex from 'prettier-plugin-apex';
const code = `public class MyClass { public static void test() { System.debug('hello'); } }`;
prettier.format(code, {
parser: 'apex',
plugins: [prettierPluginApex],
apexInsertFinalNewline: true,
}).then(result => console.log(result));
// Output:
// public class MyClass {
// public static void test() {
// System.debug('hello');
// }
// }
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-apex'
Plugin not installed or missing dependencies.
fixRun 'npm install prettier-plugin-apex --save-dev' and ensure Prettier v3 is installed.
Error: Cannot find module 'prettier-plugin-apex' from ...
Plugin is not resolved correctly in Prettier configuration.
fixSpecify full path to plugin in plugins array: `plugins: ['./node_modules/prettier-plugin-apex/dist/index.mjs']`
Error: Unknown parser: 'apex'
Plugin not properly loaded or Prettier version incompatible.
fixEnsure Prettier v3 is used and plugin is in plugins array.
TypeError: prettier.format is not a function
Using require() instead of import with ESM-only Prettier v3.
fixUse dynamic import: `const prettier = await import('prettier');` Audit
Dependencies
prettierrequiredpeer dependency; required runtime for the plugin to work