Open karlhorky opened 3 months ago
This is because the VS Code extension uses the old Prettier v2 internally - because the PR from @sosukesuzuki upgrading to Prettier v3 by default was reverted:
...and Prettier v2 (prettier@2.8.8
) also breaks with a similar error:
$ pnpm prettier --version
2.8.8
$ pnpm prettier index.js --write
[error] Invalid configuration file `index.js`: require() of ES Module /Users/k/p/prettier-vscode-10-1-0-esm-crash/prettier.config.js from /Users/k/p/prettier-vscode-10-1-0-esm-crash/node_modules/.pnpm/prettier@2.8.8/node_modules/prettier/third-party.js not supported.
[error] Instead change the require of prettier.config.js in /Users/k/p/prettier-vscode-10-1-0-esm-crash/node_modules/.pnpm/prettier@2.8.8/node_modules/prettier/third-party.js to a dynamic import() which is available in all CommonJS modules.
Add Prettier v3 to your dependencies in every project 😬
{
"type": "module",
"main": "index.js",
"dependencies": {
+ "prettier": "3.2.5"
}
}
@ntotten would you accept a new PR upgrading to Prettier v3 by default again in the Prettier VS Code extension?
Prettier v2 is pretty old now (April 2023) and the alphas of Prettier v4 are dropping now...
Just ran across this myself and thought to check the GH issues— @karlhorky instead of using a local dependency in every project there is another temporary solution that I was able to use: install prettier
globally and point the VSCode extension to that (latest) version instead:
My steps were as follows (adjust for your setup of course):
pnpm add -g prettier
settings.json
:
{
"prettier.prettierPath": "<path-to-pnpm-store>/node_modules/prettier"
}
Reloaded and everything ran sucessfully, hope this works for you and anyone else that stumbles across this bug until v3/v4 gets added!
I tried all of these settings, but none work.
Here's my prettier.config.mjs
import config from "prettier-config-atomic"
export default config
And there's the log
["ERROR" - 23:48:15] Invalid prettier configuration file detected.
{}
Summary
The Prettier VS Code extension (
esbenp.prettier-vscode@10.1.0
) currently crashes when:prettier
dependency installed inpackage.json
"type": "module"
inpackage.json
prettier.config.js
with ESMGithub Repository to Reproduce Issue
Reproduction repo: https://github.com/karlhorky/prettier-vscode-10-1-0-esm-crash
Steps To Reproduce:
Clone the reproduction repo above (or copy the code below into new files)
package.json
prettier.config.js
index.js
index.js
using the VS Code Prettier extensionExpected result
Formatting should work
Actual result
The extension crashes (see text log at bottom of issue):
This is because the VS Code extension uses the old Prettier v2 internally - because the PR from @sosukesuzuki upgrading to Prettier v3 by default was reverted:
Additional information
Feel free to attach a screenshot.
VS Code Version:
Version: 1.86.0 Commit: 05047486b6df5eb8d44b2ecd70ea3bdf775fd937 Date: 2024-01-31T10:29:11.933Z Electron: 27.2.3 ElectronBuildId: 26495564 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Darwin arm64 23.3.0
Prettier Extension Version:
esbenp.prettier-vscode@10.1.0
OS and version: macOS Sonoma 14.3 (23D56)
Prettier Log Output
cc @ntotten