18

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?

3
  • 2
    You don't need to escape quotes when you use command from cli.
    – Shlang
    Commented Jul 26, 2020 at 18:06
  • Run ls and pwd, what was the output? Commented Sep 17, 2020 at 22:32
  • What is the actual question here? Prettier is running. Do those files indeed exist and it's not finding them? Or are you expecting it to pass if they do not exist? Commented Jan 11, 2023 at 19:52

8 Answers 8

12

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

1
  • Weirdly the reverse fixed it for me
    – Yahya Fati
    Commented Jan 9 at 19:32
10

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}
9

Probably the quotes are wrong. It should probably be:

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

without the backslashes.

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"
1
  • When we removed the single quotes, it fixed the issue on windows, but our linux builds silently broke. They'd pass the linting stage but not catch any typeerrors. Basically, they stopped linting wihtout us knowing Commented Apr 18 at 17:15
4

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

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

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\" ...",
-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
1
  • 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
    Commented Dec 22, 2022 at 17:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.