You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境下配置package.json中Prettier脚本遇文件匹配错误求助

Fixing Prettier CLI "No matching files" Error on Windows

This error pops up because Windows' default command shells (CMD and PowerShell) don’t support the brace expansion syntax ({app,__{tests,mocks}__}) that works smoothly on Mac/Ubuntu’s bash/zsh. When you run the command on Windows, the shell doesn’t expand those braces into actual file paths—so Prettier ends up searching for a literal path with braces and comes up empty.

Here are several straightforward fixes to get your Prettier script working across all operating systems:

1. Split Path Patterns Explicitly

Instead of relying on brace expansion, list each target directory separately. Prettier accepts multiple path arguments, so this works reliably on Windows and Unix-like systems alike:

Update your package.json scripts section to:

"scripts": {
  "format": "prettier --single-quote --trailing-comma es5 --write \"app/**/*.js\" \"__tests__/**/*.js\" \"__mocks__/**/*.js\""
}

Note the escaped double quotes (\")—these are required because JSON uses double quotes to wrap values, so we need to escape inner quotes for the shell to interpret them correctly.

2. Move Rules to a Prettier Config File (Cleaner Approach)

To simplify your CLI command and avoid repeating formatting rules, create a .prettierrc file in your project root with your preferences:

{
  "singleQuote": true,
  "trailingComma": "es5"
}

Then your package.json script can be trimmed down to:

"scripts": {
  "format": "prettier --write \"app/**/*.js\" \"__tests__/**/*.js\" \"__mocks__/**/*.js\""
}

This keeps your scripts tidy and makes updating formatting rules much easier later on.

3. Use a Unix-Compatible Shell on Windows

If you prefer sticking with the original brace syntax, run the command in a shell that supports Unix-style expansions:

  • Git Bash: If you have Git installed on Windows, open Git Bash and run npm run format directly—Git Bash will handle the brace expansion correctly.
  • WSL (Windows Subsystem for Linux): Run your project inside a WSL environment; it behaves exactly like Ubuntu, so your original command will work without any changes.

Quick Tips

  • Windows accepts both / and \ as path separators, so you don’t need to modify the **/*.js glob patterns.
  • When using PowerShell, just run npm run format normally—it will handle the escaped quotes from your package.json correctly.

内容的提问来源于stack exchange,提问作者locropulenton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:00:32