prettier / prettier-vscode

Visual Studio Code extension for Prettier
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
MIT License
5.04k stars 446 forks source link

Version 8.0.0 errors with "Extension 'Prettier - Code Formatter' cannot format" on all documents #2029

Closed kevin-lindsay-1 closed 2 years ago

kevin-lindsay-1 commented 2 years ago

Any time I attempt to format a JSON document in 8.0.0 I get the error:

Extension 'Prettier - Code Formatter' cannot format '<document>.json'

I see no log files to assist with troubleshooting this.

Based on other users' reports, this issue appears to be happening for more than just JSON; formatting itself might not be working at all on 8.0.0.

This issue doesn't happen when rolling back to 6.4.0.

my versions:

prettier: ^2 via yarn v2 pnp prettier-vscode: 8.0.0 vscode: 1.57.1


To users experiencing this issue, you may roll back using the following steps:

  1. Go to the extensions tab
  2. Find the prettier extension
  3. Click on the settings cog
  4. Install another version...
  5. Select your desired version

Per the changelog, you should not use v7

https://github.com/prettier/prettier-vscode/blob/main/CHANGELOG.md#700

mclean25 commented 2 years ago

For the record, downgrading to 7.1.1 worked for me for formatting typescriptreact code.

kevin-lindsay-1 commented 2 years ago

I didn't downgrade to 7.x because it looked unsafe; according to GH it was released less than 24 hours ago and already jumping another major.

colbygarland commented 2 years ago

This is happening on Windows for me for any files as well

ridem commented 2 years ago

Is it the same as #2028 ? esbenp.prettier-vscode isn't even activated for me since 8.0.0

TorrenceB commented 2 years ago

I'm experiencing the same issue as well. Currently working on a windows device and I'm going to attempt @kevin-lindsay-1's solution. Can someone describe how to properly roll back Prettier version's?

kevin-lindsay-1 commented 2 years ago

@ridem It's possible that the underlying cause is that the extension either removed their registered formatters, or VS code changed their extension API and the previous registrations are no longer working, but root cause analysis is not something I'm personally focused on right now, as we have a simple workaround, and I have close to no experience building vscode extensions.

kevin-lindsay-1 commented 2 years ago

@TorrenceB

I've updated the original post with instructions.

TorrenceB commented 2 years ago

@kevin-lindsay-1 thank you for the walk-through, rolling back to 6.4.0 worked for me.

kevin-lindsay-1 commented 2 years ago

@mclean25 https://github.com/prettier/prettier-vscode/blob/main/CHANGELOG.md#700

Looks like v7 was a bad release.

williamdclt commented 2 years ago

Getting this error too. Opening the devtools tells me Activating extension 'esbenp.prettier-vscode' failed: Cannot find module 'prettier'

image
kikorp78 commented 2 years ago

When I save, prettier is removing a newline at the end of the file in v8, so I rolled back to v6. Why is it doing that?

mfeeney commented 2 years ago

Getting the same issue. Works when I roll back to 7.1.1 though.

daomtthuan commented 2 years ago

:)) "nice" update with error "can not format" ! v8.0.0 break :D roll back to 7.1.1 for fixing issue

luisgregson commented 2 years ago

Getting the same error and in Log (Extension Host) i can see this output:

[2021-06-22 17:25:29.844] [exthost] [error] Activating extension esbenp.prettier-vscode failed due to an error:
[2021-06-22 17:25:29.845] [exthost] [error] Error: Cannot find module 'prettier'
Require stack:
- /Users/luisgregson/.vscode/extensions/esbenp.prettier-vscode-8.0.0/dist/extension.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-amd.js
- /Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:934:15)
    at Module._load (internal/modules/cjs/loader.js:779:27)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
    at Function.n._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:27815)
    at Function.E._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:24567)
    at Function.c._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:93:59196)
    at Module.require (internal/modules/cjs/loader.js:1006:19)
    at v (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:698)
    at Object.2392 (/Users/luisgregson/.vscode/extensions/esbenp.prettier-vscode-8.0.0/external "util":1:26)
    at outputChannel (/Users/luisgregson/.vscode/extensions/esbenp.prettier-vscode-8.0.0/dist/extension.js:1:72851)
    at Object.9854 (/Users/luisgregson/.vscode/extensions/esbenp.prettier-vscode-8.0.0/src/LoggingService.ts:7:11)
    at r (/Users/luisgregson/.vscode/extensions/esbenp.prettier-vscode-8.0.0/dist/extension.js:1:72851)
    at /Users/luisgregson/.vscode/extensions/esbenp.prettier-vscode-8.0.0/src/extension.ts:9:1
    at /Users/luisgregson/.vscode/extensions/esbenp.prettier-vscode-8.0.0/dist/extension.js:1:74003
    at Object.<anonymous> (/Users/luisgregson/.vscode/extensions/esbenp.prettier-vscode-8.0.0/dist/extension.js:1:74024)
    at Module.u._compile (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:1315)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
    at Module.load (internal/modules/cjs/loader.js:982:32)
    at Module._load (internal/modules/cjs/loader.js:823:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
    at Function.n._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:27815)
    at Function.E._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:24567)
    at Function.c._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:93:59196)
    at Module.require (internal/modules/cjs/loader.js:1006:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Function.t [as __$__nodeRequire] (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:5:101)
    at m._loadCommonJSModule (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:25973)
    at m._doActivateExtension (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:89:12617)
    at m._activateExtension (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:89:11676)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Promise.all (index 0)

tried setting prettier.prettierPath but this didn't help unfortunately

andrevenancio commented 2 years ago

On the Settings Cog I dont have Install another version.

Screenshot 2021-06-22 at 17 43 36
MostlyEmre commented 2 years ago

I'm on Mac Mini M1 MacOS Big Sur v 11.4 and having the same issue with all my files. Using Prettier v8.0.0 on VSCode Version: 1.57.1.

MichaelXF commented 2 years ago

image

VeXell commented 2 years ago

Same problem with version 8.0.0. Reverted to 6.4 - works fine.

ntotten commented 2 years ago

Fixed in 8.0.1 - hopefully for good.

jordie23 commented 2 years ago

Fixed in 8.0.1 - hopefully for good.

I still saw this issue and VS Code said 8.0.1 was installed BUT quitting and restarting VS Code did the trick and it is now working. 👍 (and it says 8.0.1 installed)

kylekirkby commented 2 years ago

I'm still getting this issue after downgrading/removing all extensions from ~/.vscode-server-insiders/extensions/ and more. No idea what's going on and I'm banging my head against a brick wall here... :D

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true
}

is my current JSON file for testing. Prettier is formatting my JSON file correctly on save...#

Any ideas folks?

Running Ctrl + Shift + P and selecting Format(forced) works fine for me. But no errors are displaying in the terminal under any of the options selected on the right via the dropdown e.g Log (Extension Host).

I'm running Windows 10 + WSL2 with Ubuntu 20.04

Downgraded to 6.4.0

["INFO" - 6:06:06 PM] Extension Name: esbenp.prettier-vscode.
["INFO" - 6:06:06 PM] Extension Version: 6.4.0.

Yet I'm still not able to format JS files. JSON format works fine...

kevin-lindsay-1 commented 2 years ago

@kylekirkby this issue was fixed the day it happened, and by default VS Code updates extensions automatically, and I haven't seen this issue return.

I don't use insiders, but it doesn't appear obvious that insiders would be causing the problem if JSON is working.

Were your JS files being formatted correctly, specifically by prettier and not the default formatter, before?

Also, if you have a syntax error in a file prettier would probably not format it.

Additionally, this issue was specifically present in 8.0.0 and it broke the extension pretty much entirely; it was fixed in a patch about an hour later. You shouldn't need to downgrade, but if it still doesn't work after downgrading the issue is likely your setup/code. Do you have any messages coming from your linter?

kylekirkby commented 2 years ago

Hi @kevin-lindsay-1,

The prettier extension has been formatting files fine for me for months :D I know about the syntax error issue as it's a daily occurence for me.

I've finally got it working... I fixed it with:

rm -r ~/.vscode-server-insiders

So it was vscode that was messed up.. which is trange since it also was happening on a fresh clean install of VS Code (not insiders),

meastes commented 2 years ago

This issue came back for me in 8.1.0, but switching to 8.0.1 works just fine.

Edit: Was able to solve the issue by completely removing 8.1.0 from ~/.vscode/extensions and re-installing it.

Elsayed93 commented 2 years ago

For the record, downgrading to 7.1.1 worked for me for formatting typescriptreact code.

This solution works for me, Thanks :)

0xTimepunk commented 2 years ago

This is not fixed.

Running WSL2 with 8.1.0

@mclean25 please re-open

Downgrading does not help, and the only thing that helps is running the command forced

image

kylekirkby commented 2 years ago

Yep, this is definitely not fixed. We need a reproduction of this issue to fix it :/

fsrodrig commented 2 years ago

Having the same issue, the same env.

This is not fixed.

Running WSL2 with 8.1.0

@mclean25 please re-open

Downgrading does not help, and the only thing that helps is running the command forced

image

ntotten commented 2 years ago

For those having the WSL issue, open a new issue with full repro.