-
-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crashes with ESM prettier.config.js
w/out prettier
dependency in project
#3298
Comments
CauseThis 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 ( $ 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/[email protected]/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/[email protected]/node_modules/prettier/third-party.js to a dynamic import() which is available in all CommonJS modules. |
WorkaroundAdd Prettier v3 to your dependencies in every project 😬 {
"type": "module",
"main": "index.js",
"dependencies": {
+ "prettier": "3.2.5"
}
} |
Fix@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... |
prettier.config.js
without prettier
dependency in package.json
prettier.config.js
w/out prettier
dependency in project
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 My steps were as follows (adjust for your setup of course):
{
"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 import config from "prettier-config-atomic"
export default config And there's the log
|
@karlhorky Yes, absolutely. We do support prettier 3.0.0 when installed in the project, but not out of the box. We actually did release a version with 3.0.0, but it broke so we reverted and nobody has time to get back to it. Here is the revert if you want to use that as a starting point: ad1d008 I suspect it is pretty close, just need somebody to get it over the finish. |
Summary
The Prettier VS Code extension (
[email protected]
) 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
Try to format
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:
[email protected]
OS and version: macOS Sonoma 14.3 (23D56)
Prettier Log Output
cc @ntotten
The text was updated successfully, but these errors were encountered: