[英]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}"".
出现错误
[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)?你认为这是因为我在全球范围内安装了
prettier
的(在答案中它是在本地安装的)?
So how would you use pettier when it is installed globally then?那么当它被全局安装时,你将如何使用它呢?
Probably the quotes are wrong.可能引号是错误的。 It should probably be:
应该是:
prettier --write "./**/*.{js,html}"
without the backslashes.没有反斜杠。
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.
注意我在 Windows 机器上,所以不确定它在其他机器上的表现如何。 Just remove anything before and after the expression (quotes):
只需删除表达式(引号)之前和之后的任何内容:
prettier --write ./**/*.{js,html}
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这是针对 errno 2
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:如果您在
package.json
中有更漂亮的脚本设置,则需要将文件路径用引号括起来,转义双引号或使用单引号:
"prettier": "prettier 'src/**/*'"
"prettier": "prettier \"src/**/*\""
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 命令创建 your.prettierrc 文件
touch .prettierrc
put simple configuration in the.prettierrc file like将简单的配置放在 .prettierrc 文件中,例如
{
"trailingComma": "es5", "tabWidth": 4, "semi": false, "singleQuote": true } “trailingComma”:“es5”,“tabWidth”:4,“semi”:假,“singleQuote”:真}
then in the package.json file write the following script然后在 package.json 文件中写入以下脚本
"scripts": {
"prettier":"npx prettier --config .prettierrc \"src/**/*.js\" --write"
}
then run the script using npm command然后使用 npm 命令运行脚本
npm run prettier
I'm on using a windows computer.我正在使用 windows 计算机。 Removing the double quotes worked for me.
删除双引号对我有用。
this the script on package.json这是package.json上的脚本
"prettier-format": "prettier --config .prettierrc src/**/*.ts --write"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.