13

I want to add prettier into scripts in package.json.

Reading at the docs, it suggests doing the following using the cli

In practice, this may look something like:

prettier --single-quote --trailing-comma es5 --write "{app,__{tests,mocks}__}/**/*.js"

It works on mac / ubuntu but getting the following error message on windows.

[error] No matching files. Patterns tried: 'src/*.js' !**/node_modules/** !./node_modules/**
error Command failed with exit code 2.
locropulenton
  • 4,743
  • 3
  • 32
  • 57
  • Can you share exactly what was the command you added to package.json and what is the file structure of your project? – Lucas Jan 08 '18 at 15:41
  • 1
    Try referencing your file paths relative to the package.json file you're calling the script from. Prettier can't find your files because it's looking in the wrong directory. – joemaller Apr 21 '18 at 00:28

3 Answers3

11

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\"",
},
Lipis
  • 21,388
  • 20
  • 94
  • 121
8

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

ceoehis
  • 700
  • 8
  • 7
1

In my case, it was regex problem, and I simply change from "format": "prettier --write '**/*.{js,json}'" to "format": "prettier --write \"**/*.{js,json}\""