15

I found this answer how to format code using prettier

Here is what I've done

npm i prettier -g
prettier --write \"./**/*.{js,html}\"

Got an error [error] No files matching the pattern were found: ""./**/*.{js,html}"". any ideas how to fix? do you think it is because I installed the prettier globally (in the answer it is installed locally)?

So how would you use pettier when it is installed globally then?

Sergino
  • 10,128
  • 30
  • 98
  • 159

7 Answers7

9

One solution to this problem was suggested here : and actually worked for me. Notice I am on Windows machine, so am not sure how it will behave on others. Just remove anything before and after the expression (quotes):

prettier --write ./**/*.{js,html}
CyberMessiah
  • 1,084
  • 11
  • 14
8

Probably the quotes are wrong. It should probably be:

prettier --write "./**/*.{js,html}"

without the backslashes.

trusktr
  • 44,284
  • 53
  • 191
  • 263
8

the problem is with the quotes

I was using

prettier --write 'src//**/*.{js,jsx,json}'

here is how I fixed mine

prettier --write src//**/*.{js,jsx,json}

this was for errno 2

phaberest
  • 3,140
  • 3
  • 32
  • 40
Code-V
  • 101
  • 1
  • 2
5

I'm on using a windows computer. Removing the double quotes worked for me.

this the script on package.json

 "prettier-format": "prettier --config .prettierrc src/**/*.ts --write"
3

If you have a prettier script setup in package.json, you'll need to wrap the filepath in quotes, escape double quotes or use single quotes:

"prettier": "prettier 'src/**/*'"
"prettier": "prettier \"src/**/*\""
piouson
  • 3,328
  • 3
  • 29
  • 29
0

If you just want to suppress the error message, because you don't have any matching files yet, then you can use the --no-error-on-unmatched-pattern flag when executing Prettier:

$ prettier --no-error-on-unmatched-pattern --write \"./**/*.{js,html}\"
jmattheis
  • 10,494
  • 11
  • 46
  • 58
-1

what worked for me is installing touch command globally using this command

npm install touch-cli -g

then create your .prettierrc file using the touch command

touch .prettierrc 

put simple configuration in the .prettierrc file like

{ "trailingComma": "es5","tabWidth": 4,"semi": false,"singleQuote":true}

then in the package.json file write the following script

  "scripts": {
"prettier":"npx prettier --config .prettierrc \"src/**/*.js\" --write"
             }

then run the script using npm command

npm run prettier
  • 3
    Why would you install touch? It has nothing to do with the question. It just creates a file. Also I think prettier should look for .prettierrc by default without passing --config. – Aaron Dec 22 '22 at 17:49