Skip to content

Extension can't use plugin object (CLI can; Extension can use plugin's path/name string) #3641

@tomchen

Description

@tomchen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions