prettier-vscode: Prettier does not work as default formatter in VS Code 1.57.1 on Windows.

Summary

I have the Prettier extension installed, have the prettier npm package installed globally and in this project. It seems as though the Prettier extension is not starting and is missing in the VS Code status bar.

image

When I try to save a file that I know to have no errors, I get the error "Extension 'Prettier - Code fromatter' cannot format 'src\index.js'"

My relevant settings:

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

Manually formatting doesn’t work either. Running prettier in the command line does correctly format the file.

Short summary of what is going on or to provide context.

It works fine on my Mac. Both VS Code installations are fine and settings are synced.

Github Repository to Reproduce Issue

Link to a Github repo that can be used to reproduce the issue.

Steps To Reproduce:

  1. Install Prettier extension
  2. Try to save a file
  3. Alternatively, try to format manually.

Expected result

The file should have been formatted upon saving it.

Actual result

I get the error "Extension 'Prettier - Code fromatter' cannot format 'src\index.js'"

Additional information

Feel free to attach a screenshot.

VS Code Version:

Version: 1.57.1 (user setup) Commit: 507ce72a4466fbb27b715c3722558bb15afa9f48 Date: 2021-06-17T13:28:07.755Z Electron: 12.0.7 Chrome: 89.0.4389.128 Node.js: 14.16.0 V8: 8.9.255.25-electron.0 OS: Windows_NT x64 10.0.18363

Prettier Extension Version: 8.0.1

Prettier Log Output

Cannot create log output, because Prettier is missing from the toolbar.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 19 (4 by maintainers)

Most upvoted comments

okay after i updated my vscode to latest version, prettier stopped working i got the following message when i save a file at the bottom left: “prettier was unable to format /…/…/…/”

so after disable prettier and enable it again i set it as the default formatter and now its working correctly but i don’t know what happened exactly my vscode theme was reset to the default

vscode version: 1.57.1

Having the same issue on a Mac

I am wondering if that log clears out on every restart of VSCode. After closing it and restarting VSCode, the error above wasn’t in my logs anymore, just the same one you have. But my Prettier extension still wasn’t working. I rebooted the machine and it’s working now. 🙌

This version of VSCode seemed to need my permission to access the folder my code was in. A dialog popped up asking for it, which I gave. Possibly a permissions issue? That is my only guess.

Thank you for posting this so I could see it wasn’t just me! I’m glad it’s resolved for you too.

I wasn’t sure either, or aware that there were other logs. I did ctrl + shift + p, searched “log,” and selected “Developer: Open Extension Logs Folder.”

Unsure if any others with this problem have this in their exthost.log? I think I upgraded around this timestamp, but I didn’t notice the extension wasn’t working until today.

[2021-06-28 10:16:29.856] [exthost] [error] Activating extension esbenp.prettier-vscode failed due to an error:
[2021-06-28 10:16:29.856] [exthost] [error] TypeError: Cannot assign to read only property 'prettierPath' of object '#<Object>'
	at Object.t.getConfig (c:\Users\[name]\.vscode\extensions\esbenp.prettier-vscode-8.0.1\dist\extension.js:1:21612)
	at e.activate (c:\Users\[name]\.vscode\extensions\esbenp.prettier-vscode-8.0.1\dist\extension.js:1:73278)
	at Function._callActivateOptional (c:\Users\[name]\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:89:14966)

Thank you for looking at this!