简体   繁体   English

使用 prettier 时出现错误“未找到与模式匹配的文件”

[英]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.

相关问题 " Eslint "没有找到与模式 "lint" 匹配的文件。请检查模式中的输入错误。 错误 - Eslint "No files matching the pattern "lint" were found. Please check for typing mistakes in the pattern." error 故事书 6:找不到与“[项目路径]/storybook-init-framework-entry.js”匹配的文件中的错误 - Storybook 6: ERROR in No files matching '[path to project]/storybook-init-framework-entry.js' were found 使用模式匹配时的jQuery选择器优先级 - jQuery selector precedence when using pattern matching 使用显示原型模式时出现“未定义不是函数”错误 - Getting “Undefined is not a function” error when using the Revealing Prototype Pattern 将 SCSS 与 React 结合使用时出现“找不到模块”错误 - Getting "Module not found" error when using SCSS with React Django 为什么会收到此错误找不到与查询匹配的用户配置文件 - Django why getting this error No user profile found matching the query 出现 ['Unhandled Promise Rejection: Error: No matching activity!] 在 Expo913F075AEZ4E13B3F9Dandroid 模拟器上使用 WebBrowser 时出错 - Getting ['Unhandled Promise Rejection: Error: No matching activity!] error when using WebBrowser on android simulator in Expo Go 使用Prettier JS时保留then()catch()格式 - Preserve then() catch() format when using Prettier JS 无法编译; 使用 grunt 响应图像找不到有效的源文件 - Unable to compile; no valid source files were found using grunt responsive-images Vue.js 中的“找不到这些依赖项”错误 - "These dependencies were not found" error in Vue.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM