fix: resolve Windows ESM loader error (issue #3887) #3950
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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