Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

Prettier plugins (e.g., prettier-plugin-sh) can include functions in their configuration that cannot be serialized when passed across worker boundaries, causing DataCloneError. If getSupportInfo fails, the extension crashes on undefined.forEach.

Changes

  • Added sanitizePlugin() function: Recursively strips function properties from plugin objects before passing to Prettier APIs, preserving all serializable configuration
  • Error handling for getSupportInfo calls: Wrapped both invocations in try-catch with empty array fallbacks, allowing extension to continue with default language support
  • Nullish coalescing: Changed || to ?? for precise null-safety semantics
// Before: plugin objects with functions passed directly
resolvedPlugins.push(plugin);

// After: functions removed recursively
resolvedPlugins.push(sanitizePlugin(plugin));
// Before: unguarded call that can throw
const { languages } = await prettierInstance.getSupportInfo({ plugins });
languages.forEach(lang => { ... }); // crashes if getSupportInfo returns undefined

// After: graceful degradation
let languages = [];
try {
  const supportInfo = await prettierInstance.getSupportInfo({ plugins });
  languages = supportInfo?.languages ?? [];
} catch (error) {
  this.loggingService.logError("Failed to get support info...", error);
}
languages.forEach(lang => { ... }); // safe

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://storage.googleapis.com/chrome-for-testing-public/143.0.7499.4/linux64/chrome-headless-shell-linux64.zip
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/prettier-vscode/prettier-vscode/node_modules/playwright-core/lib/server/registry/oopDownloadBrowserMain.js (http block)
  • https://storage.googleapis.com/chrome-for-testing-public/143.0.7499.4/linux64/chrome-linux64.zip
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/prettier-vscode/prettier-vscode/node_modules/playwright-core/lib/server/registry/oopDownloadBrowserMain.js (http block)
  • update.code.visualstudio.com
    • Triggering command: /usr/local/bin/node node /home/REDACTED/work/prettier-vscode/prettier-vscode/node_modules/.bin/vscode-test --grep plugins -150�� test && node scripts/install-fixtures.mjs (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>DOMError when in PNPM package and using prettier plugin</issue_title>
<issue_description>### Preflight Checklist

Issue Summary

Prettier VSCode extension fails with an exception when run in a PNPM project, and prettier config has at least one plugin.

This is a follow up on #3036 and #3037 which were closed without a fix

Reproduction Repository

https://github.com/maxpatiiuk/pnpm-prettier-vscode

Steps to Reproduce

  1. Clone repository

    git clone https://github.com/maxpatiiuk/pnpm-prettier-vscode
    cd pnpm-prettier-vscode
  2. Run PNPM install:

    pnpm i
  3. Open VSCode and go to the "Output" tab.

    Open ./README.md then switch to ./test.ts.

    See exception in the console.

    Also, file is not formatted on save.

    Comment out the plugin in prettier.config.js and restart vscode - the error is gone.

Expected Behavior

No exception

Actual Behavior

Code is not reformated. VSCode Output for Prettier plugin contains:

["INFO" - 5:55:51 PM] Extension Name: esbenp.prettier-vscode.
["INFO" - 5:55:51 PM] Extension Version: 11.0.2.
["DEBUG" - 5:55:51 PM] Enabling Prettier globally
{
  "languageSelector": [
    {
      "language": "javascript"
    },
    {
      "language": "mongo"
    },
    {
      "language": "javascriptreact"
    },
    {
      "language": "typescript"
    },
    {
      "language": "typescriptreact"
    },
    {
      "language": "json"
    },
    {
      "language": "jsonc"
    },
    {
      "language": "json5"
    },
    {
      "language": "css"
    },
    {
      "language": "postcss"
    },
    {
      "language": "less"
    },
    {
      "language": "scss"
    },
    {
      "language": "handlebars"
    },
    {
      "language": "graphql"
    },
    {
      "language": "markdown"
    },
    {
      "language": "mdx"
    },
    {
      "language": "html"
    },
    {
      "language": "vue"
    },
    {
      "language": "yaml"
    },
    {
      "language": "ansible"
    },
    {
      "language": "home-assistant"
    },
    {
      "language": "jsonc",
      "scheme": "vscode-userdata"
    }
  ],
  "rangeLanguageSelector": [
    {
      "language": "javascript"
    },
    {
      "language": "javascriptreact"
    },
    {
      "language": "typescript"
    },
    {
      "language": "typescriptreact"
    },
    {
      "language": "json"
    },
    {
      "language": "jsonc"
    },
    {
      "language": "graphql"
    }
  ]
}
["DEBUG" - 5:55:55 PM] Local prettier module path: /Users/mak13180/s/e/pnpm-prettier-vscode/node_modules/prettier/index.cjs
["DEBUG" - 5:55:55 PM] Using prettier version 3.8.0
["INFO" - 5:55:55 PM] Using config file at /Users/mak13180/s/e/pnpm-prettier-vscode/prettier.config.js
["ERROR" - 5:55:55 PM] Error handling text editor change
["ERROR" - 5:55:55 PM] function({ filepath }) {
      const basename = path.basename(filepath);
      return basename === ".env" || ba...<omitted>... } could not be cloned.
DataCloneError: function({ filepath }) {
      const basename = path.basename(filepath);
      return basename === ".env" || ba...<omitted>... } could not be cloned.
    at new DOMException (node:internal/per_context/domexception:76:18)
    at p (/Users/mak13180/Documents/code/code-portable-data/extensions/esbenp.prettier-vscode-11.0.2/dist/worker/prettier-instance-worker.js:37:22)
    at /Users/mak13180/Documents/code/code-portable-data/extensions/esbenp.prettier-vscode-11.0.2/dist/worker/prettier-instance-worker.js:60:75

It seems to be trying to serialize an Error object to pass it from the worker to the main thread and fails.

When I resolve that bug by updating the extension source code to wrap the error object in a String() to make it serializable, I get the actual cause:

TypeError: Cannot read properties of undefined (reading 'forEach')
	at t.default.getSelectors (/Users/mak13180/Documents/code/code-portable-data/extensions/esbenp.prettier-vscode-11.0.2/dist/extension.js:640:19)
	at async t.default.handleActiveTextEditorChanged (/Users/mak13180/Documents/code/code-portable-data/extensions/esbenp.prettier-vscode-11.0.2/dist/extension.js:604:27)

Which happens here in the source code:

languages.forEach((lang) => {

Operating System

macOS

VS Code Version

1.108.0

Prettier Extension Version

11.0.2

Prettier Version

3.8.0

Prettier Extension Logs

...


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 17, 2026 15:49
Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix DOMError in PNPM package with Prettier plugin Fix DataCloneError with Prettier plugins containing functions in PNPM projects Jan 17, 2026
Copilot AI requested a review from ntotten January 17, 2026 15:58
@ntotten
Copy link
Member

ntotten commented Jan 19, 2026

@Copolit we need to have a test case for this in our tests to validate the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOMError when in PNPM package and using prettier plugin

2 participants