You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to install Prettier PHP Plugin in Visual Studio Code #1721
I am using Visual Studio Code for editing .php files.
How can I set up Prettier plugin to format php in vs code.
I tried to follow README.md but, I am not able to activate the code formatting on php.
I have the same issue, happen to be working on a large PHP codebase and the formatting is killing me, any help adding the plugin to already installed prettier in vscode?
I use Prettier to format on save on Vs Code.
When I use it on php files it is not working.
I installed prettier on node globally. When I use: "prettier path/to/file.php --write" it works and formats the file.
How do I add formatting php files on save ? (with Prettier PHP Plugin)
I want it to format my php files on save automatically.
Install prettier and @prettier/plugin-php locally in the root your workspace: npm install --save-dev prettier @prettier/plugin-php or yarn add --dev prettier @prettier/plugin-php
The prettier extension should ask if you want to run the local copy of prettier including all installed plugins:
If the dialog doesn't appear, try opening the package.json file.
Run "Format Document" (or enable "format on save" and save the file)
Reacted by jaxramus, webprogrammerio, Ivan Venelinov Shulev, Dragoș Mateo Dămoc, Kana Lantzsch, Reza and Gen
Thanks, @czosel, I succeeded in installing the PHP plugin but now it doesn't actually format code but gives a response on the terminal that it has formatted the code but with no effect on the code that is recognisable as change
Great, I have prettier v6.4.0 installed,
I downloaded the latest version of the PHP-plugin as at the time and installed it by "npm install --save-dev prettier @prettier/plugin-PHP
I got the prompt to allow and i "allowed everywhere"
Before following your install process I had already tried and failed to install, therefore prettier will give an error message when I tried to format PHP, the error went away after installing your way, but now I don't get any actual formatting although prettier on save will tell me in the terminal that everything is ok, also I am not using any prettier config files, just the extension settings in vs code
I installed it npm install --save-dev prettier @prettier/plugin-php but it doesn't do anything.
When I choose "Format Document" from the Command Palette, VS Code pops up to say: "There is no formatter for 'plaintext' files installed."
It then opens up the Extensions market at "category:formatters plaintext".
This is for a doc that starts <?php and ends ?>, one that is picked up as PHP elsewhere...
open the vscode terminal, to see if there's any output
there's a developer console in vscode, it should show any js exceptions when the code will not format
@UnderDogg ... I couldn't remember if this plugin was installed (doesn't appear as an extension), so (re?)-ran sudo npm install --global prettier @prettier/plugin-php...
In a PHP file, if I choose from the command palette "Format Document" (that's Prettier, right?), I still get: "There is no formatter for 'plaintext' files installed."
I have resorted to installing other PHP formatters, which correctly format the document on save. I don't know why this one won't.
Actually, I was just navigating to /usr/local/lib/node_modules/@prettier/plugin-php to delete the installed plugin and... it's not there...
@czosel The docs say to run npm install --global prettier @prettier/plugin-php. This @prettier folder is not prettier. This command creates a second folder with the @ prefix. The plugin-php is never added to prettier.
If I instead run sudo npm install --global prettier prettier/plugin-php, (no @), it still creates a folder with the @.
I wouldn't know how to answer this one.
Focus on this error: There is no formatter for 'plaintext' files installed
Check your settings, maybe .php is associated with plaintext?
Check this piece:
"files.associations": {},
Or just find plaintext in your settings.json file.
@robertandrews Yep, that's how it's supposed to be working. Inside the prettier program, all folders starting with @prettier/plugin- are searched and registered as plugins. You can verify if your installation is working by running prettier from the command line on a php file (something like yarn prettier test.php).
Install prettier and @prettier/plugin-php locally in the root your workspace: npm install --save-dev prettier @prettier/plugin-php or yarn add --dev prettier @prettier/plugin-php
In my case it was because my package.json and node_modules directories were not in the root directory I had open in VS Code (they were in a subdirectory.)
I opened that subdirectory directly and Prettier started working correctly.
Activity
czosel commentedon May 6, 2021
Hi @alexbalak21,
can you describe the steps you took in detail? As far as I know the instructions in the Readme should still be valid.
NateOs commentedon May 11, 2021
I have the same issue, happen to be working on a large PHP codebase and the formatting is killing me, any help adding the plugin to already installed prettier in vscode?
alexbalak21 commentedon May 13, 2021
I use Prettier to format on save on Vs Code.
When I use it on php files it is not working.
I installed prettier on node globally. When I use: "prettier path/to/file.php --write" it works and formats the file.
How do I add formatting php files on save ? (with Prettier PHP Plugin)
I want it to format my php files on save automatically.
czosel commentedon May 13, 2021
For me, the plugin works as expected (tested using VScode 1.56.1 with the prettier extension v6.4.0). Try the following steps:
npm install --save-dev prettier @prettier/plugin-phporyarn add --dev prettier @prettier/plugin-phpIf the dialog doesn't appear, try opening the
package.jsonfile.NateOs commentedon May 15, 2021
Thanks, @czosel, I succeeded in installing the PHP plugin but now it doesn't actually format code but gives a response on the terminal that it has formatted the code but with no effect on the code that is recognisable as change
czosel commentedon May 15, 2021
Hi @NateOs, can you share the detailed steps on how to reproduce this?
NateOs commentedon May 19, 2021
Great, I have prettier v6.4.0 installed,
I downloaded the latest version of the PHP-plugin as at the time and installed it by "npm install --save-dev prettier @prettier/plugin-PHP
I got the prompt to allow and i "allowed everywhere"
Before following your install process I had already tried and failed to install, therefore prettier will give an error message when I tried to format PHP, the error went away after installing your way, but now I don't get any actual formatting although prettier on save will tell me in the terminal that everything is ok, also I am not using any prettier config files, just the extension settings in vs code
czosel commentedon May 20, 2021
Are you sure the file you’re trying to format is valid PHP? Can you post a screenshot?
robertandrews commentedon Mar 6, 2022
I installed it
npm install --save-dev prettier @prettier/plugin-phpbut it doesn't do anything.When I choose "Format Document" from the Command Palette, VS Code pops up to say: "There is no formatter for 'plaintext' files installed."
It then opens up the Extensions market at "category:formatters plaintext".
This is for a doc that starts
<?phpand ends?>, one that is picked up as PHP elsewhere...Help.
czosel commentedon Mar 6, 2022
Does the file you’re trying to format end with “.php”? Do you have the prettier extension for vscode installed?
robertandrews commentedon Mar 6, 2022
Yes. test.php.
Yes.
czosel commentedon Mar 6, 2022
Hmm, I haven’t seen this before. Probably it would be best if you ask about this over at https://github.com/prettier/prettier-vscode
UnderDogg commentedon Mar 27, 2022
I'm a bit late to the party, but ....
robertandrews commentedon Mar 28, 2022
@UnderDogg ... I couldn't remember if this plugin was installed (doesn't appear as an extension), so (re?)-ran
sudo npm install --global prettier @prettier/plugin-php...In a PHP file, if I choose from the command palette "Format Document" (that's Prettier, right?), I still get: "There is no formatter for 'plaintext' files installed."
I have resorted to installing other PHP formatters, which correctly format the document on save. I don't know why this one won't.
Actually, I was just navigating to
/usr/local/lib/node_modules/@prettier/plugin-phpto delete the installed plugin and... it's not there...@czosel The docs say to run
npm install --global prettier @prettier/plugin-php. This@prettierfolder is notprettier. This command creates a second folder with the @ prefix. The plugin-php is never added toprettier.If I instead run
sudo npm install --global prettier prettier/plugin-php, (no @), it still creates a folder with the @.Is that the way this should be working?
UnderDogg commentedon Mar 28, 2022
I wouldn't know how to answer this one.
Focus on this error:
There is no formatter for 'plaintext' files installedCheck your settings, maybe .php is associated with
plaintext?Check this piece:
Or just find
plaintextin your settings.json file.czosel commentedon Mar 28, 2022
@robertandrews Yep, that's how it's supposed to be working. Inside the
prettierprogram, all folders starting with@prettier/plugin-are searched and registered as plugins. You can verify if your installation is working by running prettier from the command line on a php file (something likeyarn prettier test.php).jaxramus commentedon Apr 22, 2022
Installing locally and opening the
package.jsonfile worked for me. I didn't get a popup asking if I wanted to allow it everywhere though.webprogrammerio commentedon Apr 25, 2022
Thank you. This worked for me.
Gataquadrada commentedon Aug 24, 2022
Setting
prettier.resolveGlobalModulestotrueand installing it globally (npm i -g prettier @prettier/plugin-php) fixed all my issues.Paul-Hebert commentedon Jul 26, 2023
I was running into a similar issue this morning.
In my case it was because my
package.jsonandnode_modulesdirectories were not in the root directory I had open in VS Code (they were in a subdirectory.)I opened that subdirectory directly and Prettier started working correctly.
Starlette commentedon Apr 5, 2025
This is what worked for me:
What your settings.json file should look like:
Source: https://dev.to/ngobrolinit/prettier-for-php-file-formats-in-vscode-104o