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

Format document not running prettier? #388

Closed lorensr closed 6 years ago

lorensr commented 6 years ago

What's the best way to diagnose this issue? I have prettier installed and enabled. It used to work fine. I don't know when exactly it stopped working. When I have for instance this:

  <p>test</p>
<Modal     open={this.state.addingReview}        ></Modal>

And run Format Document, it results in this:

<p>test</p>
<Modal open={this.state.addingReview}      ></Modal>

Whereas running prettier from the command line results in:

<p>test</p>
<Modal open={this.state.addingReview} />
ajhyndman commented 6 years ago

Seems to me like the most recent version of VS Code has lost compatibility with this extension.

RobinMalfait commented 6 years ago

@ajhyndman I'm on the latest vscode version and the extensions still works for me.

@lorensr Do you see any errors in the prettier output window? (press the right bottom prettier item)

CiGit commented 6 years ago

Do you have multiple formatter installed? eslintIntegration?

You could try disabling prettier and see if format does the same. If so, search for the extension formatting like this.

ajhyndman commented 6 years ago

Whoah, that's weird... Thanks for the suggestion, @CiGit . I disabled the ESLint extension, and re-enabled it. Now prettier seems to be running again?

It's possible I changed something else without realizing, as well. I'll report back if any issues resurface.

lorensr commented 6 years ago

Disabling eslint and reloading has no effect. @RobinMalfait do you mean this output tab? It's not an option.

image

Prettier is def enabled:

image

Here are other extensions:

image

Bassetts commented 6 years ago

Prettier appears to have stopped working for me on version 1.22.0-insider. I don't have ESLint installed so this is definitely not causing the issue.

CiGit commented 6 years ago

@lorensr Seems the extension did not start. Can you take a look at dev console? Help -> toggle developer tools -> console

Try reinstalling:

sstimac commented 6 years ago

What happened in my case, is VSC update deleted some of my user settings, one of which was the formatOnSave , which is why the extension seemed broken ( as i'm used to format on save ).

Setting the property back was easy enough. If that's the case, check if you have "editor.formatOnSave": true set within the settings.

lorensr commented 6 years ago

My settings were intact. Here was the error:

image

Activating extensionesbenp.prettier-vscodefailed: Cannot find module 'resolve'.

Fixed by reinstalling. Did have to manually delete the folder. Thank you CiGit!

umlx5h commented 6 years ago

I have a same problem. It used to work. I tried to solve problem by @CiGit and @sstimac workaround. But It couldn't be solved. This problem was already solved? I use a latest version vscode(1.21.1) and this extension(1.2.2).

CiGit commented 6 years ago

If you have a missing dependency, reinstalling is the only thing I see.

danawoodman commented 5 years ago

For future idiots like me, make sure the file you're saving isn't in your .prettierignore file! 🤦‍♂️

amypellegrini commented 5 years ago

I run into this problem and in my particular case the "solution" required to address flow errors first, as prettier won't run if there are flow errors.

guiccbr commented 5 years ago

I had an error on my code that was preventing prettier to run. Was able to see the error through the output panel and selecting prettier on the dropdown on the right, as suggested by @RobinMalfait.

skube commented 5 years ago

For me, I don't see any errors/output from Prettier on the dropdown in the OUTPUT panel.

I'm noticing if I remove the plugin:prettier/recommended from .eslintrc:

"extends": ["airbnb","plugin:prettier/recommended"]

It works again (but obviously under different rules) so I dunno

peterbe commented 5 years ago

My problem was that I had prettier in my frontend/package.json but nothing in frontend/node_modules. The reason it's like that is because node_modules is installed inside a docker container.

My executable prettier is /Users/peterbe/.config/yarn/global/node_modules/.bin/prettier but for some reason, in this project, it couldn't use that.

xerosanyam commented 5 years ago

I had a keyword delete, because of which prettier was showing output but not formatting the code

Norfeldt commented 5 years ago

My problem was that I had prettier in my frontend/package.json but nothing in frontend/node_modules. The reason it's like that is because node_modules is installed inside a docker container.

My executable prettier is /Users/peterbe/.config/yarn/global/node_modules/.bin/prettier but for some reason, in this project, it couldn't use that.

Thank you! You pointed me to look into the package.json to find some prettier stuff that needed to be removed.

simonhaenisch commented 5 years ago

Just updated to 1.33.0 and suddenly had the same problem of it not working on save... the way I got it fixed was that I ran "Format Document" through the command palette. Then VS Code showed a notification that there are multiple formatters for .ts files installed and asked me to set a default, which added

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

to my settings. Maybe that's a feature of the new version but sadly it doesn't show the notification when trying to run the formatter by saving the file, but the default formatter thing seems to be a nice feature.

everton-e26 commented 5 years ago

thanks @simonhaenisch

I did not know how to change this file, so I am sharing this link that can be useful for anyone who has the same problem.

https://code.visualstudio.com/docs/getstarted/settings#_language-specific-editor-settings

verlok commented 5 years ago

I was getting the error "Prettier cannot format code". Uninstalling and reinstalling Prettier worked for me too.

jessepinho commented 5 years ago

For those of you using TypeScript, perhaps this is your issue: I noticed this in my VSCode settings.json:

  "[typescript]": {
    "editor.defaultFormatter": "vscode.typescript-language-features"
  },
  "[typescriptreact]": {
    "editor.defaultFormatter": "vscode.typescript-language-features"
  },

This was blocking Prettier from running on my .ts and .tsx files. Removing these fixed the issue for me.

klippx commented 4 years ago

For me this was broken in 1.34.0 and I tracked it down to config.json:

"prettier.eslintIntegration": true,

When I removed this everything worked again.

rohitkrishna094 commented 4 years ago

For anyone who reached here, you might as well try this dumb solution(which happened to work for me).

Just click on prettier button in the bottom right of your vscode application. 😅

acnevyts commented 4 years ago

My problem was my editor.formatOnSaveTimeout config somehow got changed to 0. Found this out by checking in the 'Log (Window) Output' tab.

[2019-06-06 16:06:39.432] [renderer1] [warning] Aborted format on save after 0ms

increased it to 1000 and now its working fine.

rsanath commented 4 years ago

In my case, I had this in my settings "prettier.requireConfig": true which when I removed started working.

JulianSoto commented 4 years ago

Make sure Git is up to date

xrafaelcruz commented 4 years ago

For me this was broken in 1.34.0 and I tracked it down to config.json:

"prettier.eslintIntegration": true,

When I removed this everything worked again.

Work for me, thanks :D

1729patrick commented 4 years ago

@ramsanath thanks, work for me

"prettier.requireConfig": true

deloitte-erstevens commented 4 years ago

@acnevyts thank you, this was my issue.

d-e-v-esh commented 4 years ago

I was having the same problem all of a sudden. I checked the box called "indent lines with tabs" under "prettier" in settings and checked another box called "format on save" under "editors" and that worked for me. I am a beginner so I do not have much idea about any of this still and I just messed around the settings.

klippx commented 4 years ago

Yep, issue reappeared suddenly so it's good that I am still subscribed to this thread, checking "indent lines with tabs" seems to fix it this time over 😅 👍

eminx commented 4 years ago

For me the fix was simply going to the global settings at VS Code, and checking the field at:

Preferences >> Settings >> Text Editor >> Formatting >> Format on Save (check this!)

metkerr commented 4 years ago

What happened in my case, is VSC update deleted some of my user settings, one of which was the formatOnSave , which is why the extension seemed broken ( as i'm used to format on save ).

Setting the property back was easy enough. If that's the case, check if you have "editor.formatOnSave": true set within the settings.

this work for me, thanks

diorcula commented 3 years ago

For me the fix was simply going to the global settings at VS Code, and checking the field at:

Preferences >> Settings >> Text Editor >> Formatting >> Format on Save (check this!)

This worked for me, although i am not entirely sure if it uses prettier or standard formatting from [shift] + [alt] + [f]

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.