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.
configureMonacoPrettier
✓ import { configureMonacoPrettier } from 'monaco-prettier'
✗ const { configureMonacoPrettier } = require('monaco-prettier')
This package is ESM-only (exports field in package.json). CommonJS require will fail.
setup
✓ import { setup } from 'monaco-prettier/worker'
✗ import { setup } from 'monaco-prettier'
setup is exported from the subpath 'monaco-prettier/worker', not the main package.
default import
✓ import monacoPrettier from 'monaco-prettier'
Default export is the configureMonacoPrettier function (named export is preferred).
Shows how to set up a Prettier worker and configure Monaco to use it for formatting JavaScript files.
// prettier.worker.js
import { setup } from 'monaco-prettier/worker';
import * as babel from 'prettier/plugins/babel';
import * as estree from 'prettier/plugins/estree';
setup([babel, estree]);
// app.js
import * as monaco from 'monaco-editor';
import { configureMonacoPrettier } from 'monaco-prettier';
globalThis.MonacoEnvironment = {
getWorker(moduleId, label) {
if (label === 'prettier') {
return new Worker(new URL('prettier.worker.js', import.meta.url));
}
return new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker.js', import.meta.url));
}
};
monaco.languages.typescript.javascriptDefaults.setModeConfiguration({
documentFormattingEdits: false,
documentRangeFormattingEdits: false
});
configureMonacoPrettier(monaco, {
parsers: {
javascript: 'babel',
typescript: 'babel-ts'
},
prettier: {
semi: false,
singleQuote: true
}
});
monaco.editor.createModel('const x = 1', 'javascript', monaco.Uri.parse('file:///test.js'));
Errors
Common errors & fixes
Error: Module not found: 'monaco-prettier/worker'
Using a bundler that doesn't support package.json exports (e.g., older webpack) or not running in a worker context.
fixEnsure your bundler supports the 'exports' field or import from the resolved path. Alternatively, use a dynamic import in a worker file.
TypeError: configureMonacoPrettier is not a function
Importing the default export instead of named export, or CommonJS require failing.
fixUse import { configureMonacoPrettier } from 'monaco-prettier' . If using CJS, switch to ESM. The builtin formatting continues to override Prettier output
Did not disable Monaco's built-in formatting providers for the target language.
fixCall setModeConfiguration for each language as shown in the quickstart.
Prettier worker not loading: Error: Unknown label prettier
MonacoEnvironment.getWorker does not have a case for 'prettier' label.
fixAdd a case for label 'prettier' that returns your worker. The worker URL must match your bundler's setup.
Audit
Dependencies
prettierrequiredPeer dependency; the package uses Prettier's formatting APIs.