Sergino
Sergino

Reputation: 10838

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

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?

Upvotes: 20

Views: 34678

Answers (8)

Adam Hughes
Adam Hughes

Reputation: 16319

Other answers have suggested for Windows, drop the single quotes. IE:

"npx eslint 'src/**/*.ts' ...",

Becomes

"npx eslint src/**/*.ts ...",

This can cause linux builds to stop linting. We started having typeerrors in deployments and the linter was not catching anything after this change. Instead, I recommend escaping the quotes.

 "npx eslint \"src/**/*.ts\" ...",

Upvotes: 0

jmattheis
jmattheis

Reputation: 11135

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

Upvotes: 4

victor quijada
victor quijada

Reputation: 51

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"

Upvotes: 5

Omar A. El Sabagh
Omar A. El Sabagh

Reputation: 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

Upvotes: -1

piouson
piouson

Reputation: 4565

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

Upvotes: 4

CyberMessiah
CyberMessiah

Reputation: 1268

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}

Upvotes: 10

Code-V
Code-V

Reputation: 161

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

Upvotes: 14

trusktr
trusktr

Reputation: 45504

Probably the quotes are wrong. It should probably be:

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

without the backslashes.

Upvotes: 9

Related Questions