Getting an error 'No files matching the pattern were found' when using prettier

28.2k Views Asked by At

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?

7

There are 7 best solutions below

1
On

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

0
On

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}
0
On

Probably the quotes are wrong. It should probably be:

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

without the backslashes.

0
On

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}\"
0
On

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/**/*\""
1
On

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
0
On

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"