prettier-vscode
prettier-vscode copied to clipboard
Extension can't use plugin object (CLI can; Extension can use plugin's path/name string)
Summary
Extension shows error while CLI is good with a local custom plugin.
Edit: it seems Extension can't use a imported plugin configuration object (but CLI can). Extension can only use plugin's path/name string
Steps To Reproduce:
- New folder,
npm init -y, latest VS Code, install latest Prettier extension and set it as default JS formatter, prettier not installed globally with npm npm install -D prettier- Add ./prettier.config.mjs:
import customPlugin from "./prettier-plugin-custom.mjs";
export default {
plugins: [customPlugin],
};
- Add ./prettier-plugin-custom.mjs:
import { parsers as parsersBabel } from "prettier/plugins/babel";
export default {
parsers: {
babel: parsersBabel.babel,
},
};
npx prettier --write prettier-plugin-custom.mjs-> No problem- Shift + Alt + F to format prettier-plugin-custom.mjs -> Error, log simply shows
Invalid prettier configuration file detected. See log for details.
Additional information
VS Code Version:
Latest
Version: 1.98.0 (user setup)
Commit: 6609ac3d66f4eade5cf376d1cb76f13985724bcb
Date: 2025-03-04T21:06:18.612Z
Electron: 34.2.0
ElectronBuildId: 11044223
Chromium: 132.0.6834.196
Node.js: 20.18.2
V8: 13.2.152.36-electron.0
OS: Windows_NT x64 10.0.26100
Prettier Extension Version: Latest 11.0.0
OS and version: Windows 11
Prettier Log Output
Simply
Invalid prettier configuration file detected. See log for details.
I don't see any details
Further attempts
I changed Node.js from v22.13.1 to v20.18.2 with nvm to align with VS Code Electron's Node version to see if it is caused by that, but CLI is still good.
I changed the files to Common JS:
prettier.config.cjs
const customPlugin = require("./prettier-plugin-custom.cjs");
module.exports = {
plugins: [customPlugin],
};
prettier-plugin-custom.cjs
const { parsers: parsersBabel } = require("prettier/parser-babel");
module.exports = {
parsers: {
babel: parsersBabel.babel,
},
};
Still CLI good extension bad
Invalid prettier configuration file detected. See log for details.
This is the most frustrating thing about this issue - there is no log that shows anything other than this message. Combined with the fact that it works fine on the command line it makes this completely impossible to debug.
Help -> Toggle developer tools in vscode may be helpful. This at least lets me see console.log statements in the prettier file. In my case the prettierrc is loading fine, so I think it's something in prettier or this plugin that then throws for some reason?
Changing to use plugins: ['prettier-plugin-svelte'] rather than plugins: [ require('prettier-plugin-svelte') ] seems to fix it which is odd. Does prettier not allow loading plugins like this anymore? But then why does it work on the CLI?
It appears related to https://github.com/prettier/prettier/discussions/15167 so potentially something to do with RPC boundaries and the fact that required modules cannot be sent to the appropriate worker thread.
I was able to workaround it with:
import url from 'node:url';
export default {
...,
plugins: [
url.fileURLToPath(import.meta.resolve('prettier-plugin-packagejson')),
]
}
But the simple string works too if it's in the root node_modules (I'm using a monorepo approach with PNPM which does not hoist plugins by default anymore)
We're also using pnpm but we've added public-hoist-pattern[]='prettier-plugin-svelte' to .npmrc to hoist it.
The fileURLToPath example is useful though, I might try that instead.
OK. Updated the title and summary
This issue has been labeled as stale due to inactivity. Reply to keep this issue open.
Even if this isn't something that prettier-vscode can fix, it does at least need documenting.