fix: resolve Windows ESM loader error (issue #3887)#3950
fix: resolve Windows ESM loader error (issue #3887)#3950moshkinura wants to merge 2 commits intoprettier:mainfrom
Conversation
Fix activation error on Windows: 'Only URLs with a scheme in: file, data, node, and electron are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol d:.' Changes: - Remove 'type: module' from package.json (VS Code extension host doesn't support native ESM extensions) - Revert esbuild node config to CommonJS format (cjs) with platform: 'node' - Remove unnecessary external modules from esbuild config - Fix createRequire() in resolvers.ts to use pathToFileURL() for Windows compatibility This reverts the ESM conversion from commit 74b56c7 and restores the working CJS configuration from v12.0.4, which is compatible with VS Code extension host on all platforms (Windows, Linux, macOS). The error was specific to Windows because Node.js ESM loader requires file:// URLs for absolute paths on Windows, but VS Code extension host doesn't support native ESM extensions yet.
|
Would be nice to have this merged |
|
VS Code 1.100 and Antigravity (based on VS Code v1.104.0), both released in December or earlier, support ESM extensions. Cursor, however, despite claiming to be based on VS Code v1.105.1 since December, did not support ESM. After Cursor 2.4.21 introduced a fix for Linux a week ago, this has now become a Cursor-on-Windows-only problem. I can confirm that on Windows, the latest VS Code and Antigravity do not have this issue with the latest Prettier extension. Therefore, it is logically Cursor's responsibility to fix this, not the extensions'. Instead of spending so much effort repeatedly breaking the UI layout in every release, Cursor should focus on something more important, like the ESM issue. The core maintainer of the Prettier extension has already spoken against rolling back to CJS when this was a Cursor-only issue. Now that it is a Cursor-on-Windows-only problem, rolling back to CJS makes even less sense. |
Description
This PR fixes the extension activation error on Windows that occurs after the ESM conversion in commit 74b56c7. The error message is:
Activating extension 'prettier.prettier-vscode' failed: Only URLs with a scheme in: file, data, node, and electron are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'.Root Cause:
VS Code extension host does not support native ES Module (
"type": "module") extensions. The ESM conversion attempted to use native ESM format, which is incompatible with the VS Code extension host on all platforms, but the error manifests specifically on Windows due to how Node.js ESM loader handles absolute paths.Solution:
"type": "module"frompackage.jsonto restore CommonJS compatibilityformat: "cjs",platform: "node")createRequire()inresolvers.tsto usepathToFileURL()for proper Windows path handlingThis restores the working configuration from v12.0.4, which uses CommonJS format compatible with VS Code extension host on all platforms (Windows, Linux, macOS).
Related Issue
Fixes #3887
Type of Change
Checklist
npm run lintpasses)npm run prettierto format my codenpm test)Additional Notes