Skip to content
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

Format on Save (prettier) stopped working with latest update #108447

Closed
ivanjeremic opened this issue Oct 10, 2020 · 86 comments
Closed

Format on Save (prettier) stopped working with latest update #108447

ivanjeremic opened this issue Oct 10, 2020 · 86 comments
Assignees
Labels
formatting Source formatter issues *question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@ivanjeremic
Copy link

Format on Save (prettier) stopped working with the latest update

Multiple time reinstalled Prettier, and checked the settings, it happened right after the update of VSCode.

https://gyazo.com/f07a3bfd0733edeed2a8d213fc3d21ac

@nofear-js
Copy link

Same problem

@j-francisco
Copy link

Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null.

@frandmb
Copy link

frandmb commented Oct 11, 2020

Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null.

Worked for me, thank you!

@pgmoir
Copy link

pgmoir commented Oct 11, 2020

Yes, it worked as default formatter, but surely I shouldn't have to set default formatter for vscode. It should be on a project by project basis.

@jannomeister
Copy link

Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null.

This worked for me also but there's some scenarios where I just want prettier for a specific project and not globally 😢

@nicolasrouanne
Copy link

Same for me, selecting prettier as default formatter for VSCode works, but this prevents from working with other languages. I'm using ruby as well, and I've got the same problem with rubocop formatter: it stopped working as of 1.50.0.
And I can't have 2 different default formatters globally for VSCode.

@AlissonRS
Copy link

AlissonRS commented Oct 12, 2020

Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null.

In case anyone is having issues finding the option @j-francisco explained above:

File -> Preferences -> Settings (for Windows)
Code -> Preferences -> Settings (for Mac)

Search for "Default Formatter". In the dropdown, prettier will show as esbenp.prettier-vscode.

image

@MichelKansou
Copy link

@AlissonRS Thx

@iNishant
Copy link

The above solution by @j-francisco and @AlissonRS fixes the prettier issue but for me, but all other language settings have been messed up too. For python, we use black formatter and now that's not working because I have selected prettier as the default formatter. If I select black as default then prettier won't work on js files. Seems like auto detect language and formatter is not working. Any idea how I could fix this?

@madsh93
Copy link

madsh93 commented Oct 13, 2020

I understand the frustation from people who are dependent on this. I use other tools such as Headwind, which now does not work.

@kud
Copy link

kud commented Oct 13, 2020

Same here. Is it a breaking change from VS Code or is it prettier which changed its namespace/code name?

@ivanjeremic
Copy link
Author

ivanjeremic commented Oct 13, 2020

I fixed it and now it broke again from alone, this has no effect #108447 (comment) Edit Fixed it again by directly searching Format on Save and activate it.

@jrieken jrieken added formatting Source formatter issues info-needed Issue requires more information from poster labels Oct 15, 2020
@jrieken
Copy link
Member

jrieken commented Oct 15, 2020

So, what's the issue here? Is it that the settings (editor.defaultFormatter) isn't alive anymore? Or is it that the setting for format on save (which is off by default) (editor.formatOnSave) isn't set?

@AlissonRS
Copy link

AlissonRS commented Oct 15, 2020

@jrieken it's not related to editor.formatOnSave, the problem is prettier stopped working, even manual formatting (SHIFT + ALT + F) wasn't working, and it worked again after setting editor.defaultFormatter to prettier. What is not clear to me is if new VS Code just accidentally removed editor.defaultFormatter (updated it to null), or if editor.defaultFormatter has always been null but previous VS Code versions were able to handle it properly and still make prettier work.

@jrieken
Copy link
Member

jrieken commented Oct 15, 2020

What is not clear to me is if new VS Code just accidentally removed editor.defaultFormatter (updated it to null), or if editor.defaultFormatter has always been null but previous VS Code versions were able to handle it properly and still make prettier work.

Yeah, that's the question. Out of the box, editor.defaultFormatter is null. Also, note that the setting can be configured per language - something the UI doesn't support and that needs the JSON-based editor

@ivanjeremic
Copy link
Author

So, what's the issue here? Is it that the settings (editor.defaultFormatter) isn't alive anymore? Or is it that the setting for format on save (which is off by default) (editor.formatOnSave) isn't set?

Both in my case, first the editor.defaultFormatte was null, after I fixed it one day later the (editor.formatOnSave) was not active anymore.

@jrieken
Copy link
Member

jrieken commented Oct 15, 2020

@ivanjeremic Do you use settings sync?

@ivanjeremic
Copy link
Author

@ivanjeremic Do you use settings sync?

Yes I do.

@kud
Copy link

kud commented Oct 15, 2020

I don't any settings sync and yeah my editor.defaultFormatter was null instead of esbenp.prettier-vscode. Maybe they changed their codename.

Anyway, here, since I set the right formatter, I'm good. 👍🏻

@ap00rv
Copy link

ap00rv commented Oct 16, 2020

I am experiencing same behavior as @nicolasrouanne . If I set prettier as formatter in user settings, then only it works. If I set it only in workspace settings for my TS project, it does not work. This isn't ideal for people working on languages other than TS/JS.

@jrieken
Copy link
Member

jrieken commented Oct 16, 2020

@ap00rv I have tried that and I cannot reproduce. I have prettier installed and configured to be the default formatter for typescript-files and format on save works for me.

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

Can you (or someone) share reproducible steps with me?

@ap00rv
Copy link

ap00rv commented Oct 16, 2020

Hi @jrieken , can you try using the above settings only at workspace level ( default formatter in user setting should be null) and then see what happens ?

@jrieken
Copy link
Member

jrieken commented Oct 16, 2020

Yeah, that's what I have.

@ap00rv
Copy link

ap00rv commented Oct 16, 2020

ok, my apologies. It is working for me now after setting the following in workspace setting only . Sorry for the trouble.

"editor.codeActionsOnSave": {
      // For ESLint
      "source.fixAll.eslint": true
    },
    "[typescript]": {
      "editor.defaultFormatter": "esbenp.prettier-vscode"
    },

@dlsso
Copy link

dlsso commented Oct 16, 2020

All my coworkers and I are on VS Code 1.50.1 and Prettier extension 5.7.1, but some are seeing the issue and some not, so something else is at play here.

@ap00rv
Copy link

ap00rv commented Oct 18, 2020

@dlsso for those of your colleagues facing issues, you may want to check if the default formatter setting in workspace is being overriden somewhere else. Thats what happened in my case. ESlint linting should be configured using different option as given here

@lleonardoprado
Copy link

Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null.

Thank you, worked for me!

@kdzapp
Copy link

kdzapp commented Nov 10, 2020

Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null.

Thank you!! When prettier started working again I felt like I could breath again 😂

@bnitin92
Copy link

Thank you for the setting, worked for me.

@jahanner
Copy link

jahanner commented Nov 12, 2020

Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null.

@j-francisco Came in clutch, thanks

@BenHurMartins
Copy link

Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null.

worked as a glove, thanks

@parnekov
Copy link

Put this fields to settings.json

"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}

cleack5 pushed a commit to cleack5/css that referenced this issue Nov 18, 2020
参考:microsoft/vscode#108447 (comment)

File -> Preferences -> Settings (for Windows)
Code -> Preferences -> Settings (for Mac)

Search for "Default Formatter". In the dropdown, prettier will show as esbenp.prettier-vscode.
@IRediTOTO
Copy link

Me too

@juniordnts
Copy link

I'm about to roll back to the working vscode. Now it's just buggy. In some directories it does format, in others just don't. I tried:

"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSaveMode": "file"

This didn't work.

The funny thing is: In my node project any "format on save" work. But in my PHP project all format on all files works normaly.

@PsionicChic
Copy link

Here's what worked for me:
set Default Formatter to 'esbenp.prettier-vscode'
set Format On Save is checked and mode is 'file'
...
I also had to turn Auto-Save to 'off' <=== this is what made it happen for me

@adelriosantiago
Copy link

Just a reminder: If after setting the defaultFormatter to esbenp.prettier-vscode it still doesn't work. You may have an error in your JS/HTML. Take a look at the output (down-right part of the screen) as shown below to see which line is causing Prettier to fail.

image

@deadlysyn
Copy link

My biggest problem is after setting a defaultFormatter, anything not formatted with Prettier (Go, Terraform, etc) throws "prettier can't format this file". It's odd to me that this all worked great for years, but now breaks...and even the workarounds are fragile...but this isn't a regression. I need to spend the weekend going through settings with a fine toothed comb. :-(

@mddilley
Copy link

mddilley commented Nov 24, 2020

I struggled with this issue as well when formatting on save with Prettier for JS and Black for Python. These settings used to coexist great but something changed. I had success by setting editor.defaultFormatter per language in my settings.json. Switching default each time I worked on a different codebase was not ideal, so this made me very happy.

{
  <all the other stuff>,
  "editor.formatOnSave": true,
  "python.formatting.provider": "black",
  "python.formatting.blackPath": "black",
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[python]": {
    "editor.defaultFormatter": null
  },
}

@deadlysyn
Copy link

Thank you for sharing @mddilley -- this will save my sanity, but also find the need for so much more configuration just to maintain prior behavior infuriating. Was there a technical reason for this change? Someone thought it was good DevEx? Curious minds want to know.

@szobonyatomi
Copy link

no work with php, (html, css OK)

@xavierhazzardadmin
Copy link

Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null.

In case anyone is having issues finding the option @j-francisco explained above:

File -> Preferences -> Settings (for Windows)
Code -> Preferences -> Settings (for Mac)

Search for "Default Formatter". In the dropdown, prettier will show as esbenp.prettier-vscode.

image

This didn't work for me

@wyeo
Copy link

wyeo commented Dec 4, 2020

@xavierhazzardadmin look inside your settings.json file :

  • Windows : %APPDATA%\Code\User\settings.json
  • macOS : $HOME/Library/Application Support/Code/User/settings.json
  • Linux : $HOME/.config/Code/User/settings.json

@harukaeru
Copy link

Perhaps it was only to me, but it happened because I'd forgotten to lay .prettierrc at the top-level. As @adelriosantiago mentioned, you can see logs as follows.
image

Once I lay the config file properly, it was all fixed.
Yeah, if there were no config, prettier can't know how to prettify my codes... I was dumb.

@deadlysyn
Copy link

@paullewisn i'm no expert, just someone who finds it infuriating when i need to spend a week re-configuring a "tool" that's supposed to help make me productive :-) so maybe something in this will help you... if you haven't already, try a few things (some as a direct fix, some to prevent other problems):

ctrl-, and make sure "editor: default formatter" setting is null. this is so the explicit ones you specify are in full control with no surprises. unless you only work in one language, whatever you set this to will be wrong in some files and cause confusion.

double check "Editor: Format On Save" is checked while in settings, it should be per your settings.json. trust byt verify.

adjust "Editor: Format On Save Mode" -- some have reported it only works properly when set to "file".

in settings.json, make sure files.autoSave is off. this is called out in "Format on Save" setting description and some plugin readmes.

if it still doesn't work after all that, consider having vscode run eslint, and eslint in turn call prettier...this gets the best of both tools and has ran w/o problems for years (minus the default formatter changes that broke the whole chain). if you go this route, you'll need a small amount of config for each tool + appropriate project dependencies installed. there are a lot of online articles to help with that, here's one:

https://dev.to/thetinygoat/prettier-eslint-setup-for-vscode-5b6

good luck!

@appyofficial
Copy link

Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null.

Worked!!! 🍡

@deadlysyn
Copy link

@appyofficial that will work great, until you try to work in a file prettier doesn't handle... keeping default null and having per-language settings is required if you work in languages not supported by prettier. otherwise things like terraform, go, etc. will get errors on each save about unsupported formatter.

if this works for you, great... KISS. :-)

@Redskinsjo
Copy link

Perhaps it was only to me, but it happened because I'd forgotten to lay .prettierrc at the top-level. As @adelriosantiago mentioned, you can see logs as follows.
image

Once I lay the config file properly, it was all fixed.
Yeah, if there were no config, prettier can't know how to prettify my codes... I was dumb.

How do you configure the config files ?

It says to me
Capture d’écran 2020-12-18 à 20 06 21

should i create a .prettierrc file at the root of my project and set some of the properties suggested ?? but which ?

@deadlysyn
Copy link

@Redskinsjo that will be somewhat personal-preference/project specific, but you can start with something like:

# .prettierrc
{
  "printWidth": 80,
  "singleQuote": true,
  "tabWidth": 2,
  "semi": false
}

# .prettierignore
package.json
package-lock.json

then extend as needed:

https://prettier.io/docs/en/configuration.html

@Redskinsjo
Copy link

i created a .prettierrc and a .prettierignore file at the root of my project, but Prettier still doesn't work.

@Redskinsjo

This comment has been minimized.

@harikrishnan-u01
Copy link

Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default Formatter was null.

Worked for me. Thanks a lot.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
formatting Source formatter issues *question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests