It helped for me let's try:
npm install -g prettier
Answer from Dheeraj Maheshwari on Stack OverflowHey all - can't figure this one out.
I followed the instructions here, and just can't get the "prettier" command to output anything other than "zsh: command not found: prettier." Instructions: https://developer.salesforce.com/tools/vscode/en/user-guide/prettier
I have NPM (6.14.15) and Node (v14.17.6) installed. Anyone know what I am doing wrong?
Videos
It helped for me let's try:
npm install -g prettier
First check if Node is accessible for you.
node -v should show some version number
Regarding the command not found.
This happens in a Windows machine. You need to add the npm path in Environment variables path
The path value will be C:\Users\YOUR-USERNAME\AppData\Roaming\npm
- Right click This PC
- Properties Advanced system settings -> Advacnced tab -> Environment variables
- Under User variables Click path, then click Edit Append the path value (sample I pasted above.)
Now exit all command prompt windows and try your commands
Here is an image of my terminal: https://snipboard.io/iSjD2L.jpg
For reference, I am using a Macbook 2017 Bash terminal.
Installing a module that includes a CLI program like prettier, nodemon, etc., will place the program in node_modules/.bin. Your terminal shell does not know to look in this folder when you run a command. Type echo $PATH in your terminal to see a list of the folders that are checked when you run a command. You'll see that running prettier will be looking in places like /bin, /usr/bin, /usr/local/bin, etc., but definitely not /var/folders/q6/npwl_7xj4wg91lg06f8pnnfh0000gn/T/node_modules.
This is why npx is often used; from their docs:
Executes either from a local node_modules/.bin, or from a central cache, installing any packages needed in order for to run.
You could also run it via ./node_modules/.bin/prettier, or you could install it globally, as you ultimately did, which will put it in a place that is part of your $PATH.
After trying a bunch of things, I noticed it only affected this one folder. So what finally worked was simply cloning the repo again into a different folder.
Some times with auto plugins update Required files used by Prettier might go missing .
Check this path if files are present here or folder is empty
C:\Users\YOURUSERNAME\.vscode\extensions\esbenp.prettier-vscode-2.2.2\out
If missing uninstall and reinstall prettier
I Rolling back prettier to 1.7.3 and fixed it
Hi there,
I'm using VS Code on Windows 11, and I have installed Prettier. However, I can only use it from the terminal.
If I execute npx Prettier --write dom.html in the terminal, it works fine.
If I go to the Command Palette and choose Format Document, the following error appears in the output:
["ERROR" - 10:38:49 AM] Invalid prettier configuration file detected. ["ERROR" - 10:38:49 AM] ENOENT: no such file or directory, open 'c:\Users\ivanf\Dropbox\dev\FrontEndBootCamp - Exercises\firstjs\ C:\Users\ivanf\AppData\Roaming\npm\prettier' Error: ENOENT: no such file or directory, open 'c:\Users\ivanf\Dropbox\dev\FrontEndBootCamp - Exercises\firstjs\ C:\Users\ivanf\AppData\Roaming\npm\prettier'
To make it more clear,
c:\Users\ivanf\Dropbox\dev\FrontEndBootCamp - Exercises\firstjs\ is the project folder, and \Users\ivanf\AppData\Roaming\npm\prettier is where prettier is installed.
So it seems that in some configuration file the wrong path "PROJECT_FOLDER PRETTIER_HOME" is formed.
Unfortunately, I cannot locate such file, and I cannot understand why it works when called from the terminal.
Any advice or hints? Thank you in advance, Ivan.
For Windows you have to escape the ", in the package.json will look like this:
"scripts": {
"prettier": "prettier --single-quote --trailing-comma es5 --write \"{app,__{tests,mocks}__}/**/*.js\"",
},
I encountered this issue most recently myself.
Here's what I did:
in my package.json file i added this to the scripts section:
"scripts": {
"format": "prettier --write src/**/*.js",
}
Note that the path does not have its own set of quotes. That solved it for me