简体   繁体   English

“没有找到与模式“src”匹配的文件。” 使用“npx eslint src”或“npx eslint src/”时

[英]"No files matching the pattern "src" were found." when using "npx eslint src" or "npx eslint src/"

I've just set up a create-react-app project with typescript.我刚刚用打字稿建立了一个 create-react-app 项目。 I've added eslint with npx eslint --init .我已经用 npx eslint --init 添加了npx eslint --init When I run npx eslint src/ or npx eslint src I get an error:当我运行npx eslint src/npx eslint src时出现错误:

Oops! Something went wrong! :(

ESLint: 8.18.0

No files matching the pattern "src" were found.
Please check for typing mistakes in the pattern.

However, if I use this command: npx eslint src/* then it works.但是,如果我使用这个命令: npx eslint src/*那么它就可以工作。 This is fine, but some guides and stackoverflow comments ( eg on here ) I've seen show that the commands that don't work for me are working for seemingly everyone else.这很好,但是我看到的一些指南和 stackoverflow 评论( 例如在这里)表明,对我不起作用的命令似乎对其他所有人都有效。 What am I doing wrong?我究竟做错了什么?

eslint.js

module.exports = {
  env: {
    browser: true,
    es2021: true,
    jest: true,
  },
  extends: ["plugin:react/recommended", "standard"],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: "latest",
    sourceType: "module",
  },
  plugins: ["react", "@typescript-eslint"],
  rules: {
    semi: "off",
    quotes: "off",
    "space-before-function-paren": "off",
  },
  ignorePatterns: ["**/*.css", "**/*.svg"],
};

package.json : package.json

 "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^13.0.0",
    "@testing-library/user-event": "^13.2.1",
    "@types/jest": "^27.0.1",
    "@types/node": "^16.7.13",
    "@types/react": "^18.0.0",
    "@types/react-dom": "^18.0.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "typescript": "^4.4.2",
    "web-vitals": "^2.1.0"
  },
    "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.30.0",
    "@typescript-eslint/parser": "^5.30.0",
    "eslint": "^8.0.1",
    "eslint-config-standard": "^17.0.0",
    "eslint-plugin-import": "^2.25.2",
    "eslint-plugin-n": "^15.0.0",
    "eslint-plugin-promise": "^6.0.0",
    "eslint-plugin-react": "^7.30.1"
  },

Okay the comments I left were incorrect.好吧,我留下的评论不正确。 This question left me reading about ESLint, how it works, and how the npm / npx commands differ.这个问题让我了解了 ESLint,它是如何工作的,以及npm / npx命令有何不同。

So here is the deal所以这里是交易

NOTE: "I use the syntax $(pwd) to refer to the current-working-directory, because it's not a pseudo representation of a path, but rather a command, wrapped as such, that it can be interpreted, and ran, by the BASH shell."注意: “我使用语法$(pwd)来引用当前工作目录,因为它不是路径的伪表示,而是一个这样包装的命令,它可以通过以下方式解释和运行BASH外壳。”

In the comments, I wrote about eslint resolving paths, and its inability to infer the meaning of the CLI passed argument src , as shown in this snippet:在评论中,我写了 eslint 解析路径,以及它无法推断CLI传递的参数src的含义,如以下代码片段所示:

  /* COMMAND-1 */

  $ eslint src

Thinking back on it, that was a really dumb comment to make, that I shouldn't have said.回想起来,这是一个非常愚蠢的评论,我不应该说。 The reason it wasn't smart, is because, the way the path is resolved completely changes when you use the following:它不聪明的原因是,当您使用以下内容时,解析路径的方式会完全改变:

  /* COMMAND-2 */

  $ npx eslint src

Looking at the two commands together, side by side, is helpful in the sense that it allows us to draw a side by side comparison, however, there really isn't much to compare, because of how different these two commands are.并排查看这两个命令是有帮助的,因为它允许我们进行并排比较,但是,由于这两个命令有很大的不同,因此实际上没有太多可比较的地方。

So the first command, COMMAND-1 , resolves src as if it were a path, however, COMMAND-2 executes an ESLint internal command, hence the "X" in npx , which is the same as executing...因此,第一个命令COMMAND-1将 src 解析为路径,但是COMMAND-2执行npx内部命令,因此 npx 中的“X”与执行...相同

npm exec or npm x npm execnpm x

In other words, the following;换句话说,如下; npx eslint src can also be executed using npm x eslint src , or npm exec eslint src . npx eslint src也可以使用npm x eslint srcnpm exec eslint src

So, as stated above, **the argument src is not a system file-path , but rather, it's an internal ESLint command that offers a cute little CLI printout of your errors.因此,如上所述,**参数src不是系统file-path ,而是一个内部 ESLint 命令,它提供了一个可爱的小 CLI 打印输出您的错误。 ITS ACTUALLY PRETTY COOL它实际上很酷


Initially the Command didn't work for me either最初命令对我也不起作用

The problem I had, looks, like it was the same problem your having.我遇到的问题,看起来和你遇到的问题一样。

The solution is quite simple.解决方案非常简单。
  1. Update NPM to the latest version.将 NPM 更新到最新版本。
  2. Update NPX to the latest version.将 NPX 更新到最新版本。 (more on this below) (更多内容如下)
  3. Update Node.js to the latest version将 Node.js 更新到最新版本
  4. Update ESLint to the latest version更新 ESLint 到最新版本
  5. Update all of your proj's pkgs, then audit them with the fix command (more on this below).更新所有项目的 pkg,然后使用 fix 命令审核它们(更多内容见下文)。

So NPM comes with the NPX command embedded in it, and technically, npx is the npm command, just ran as npm x or npm exec , however;所以 NPM 带有嵌入其中的 NPX 命令,从技术上讲, npxnpm命令,只是作为npm xnpm exec from the standpoint of your file-system, (in other words, looking at the commands from the context of /usr/bin/... ) they are two different commands.从您的文件系统的角度来看,(换句话说,从/usr/bin/...的上下文中查看命令)它们是两个不同的命令。

So I know alot about ubuntu because it was my OS for 7 years.所以我对 ubuntu 了解很多,因为它是我 7 年的操作系统。 About a year ago I switched to Fedora 36: Workstation and was glad I did.大约一年前,我切换到Fedora 36: Workstation ,很高兴我做到了。 I made the change because of the issues associated with installing Node.js & NPM.由于与安装 Node.js 和 NPM 相关的问题,我进行了更改。 Ubuntu makes it difficult. Ubuntu让它变得困难。 The reason I use Linux in the first place is because software runs in an environment that suited for running software, and not suited for protecting the proprietary licenses associated with the software.我首先使用 Linux 的原因是因为软件在适合运行软件的环境中运行,而不适合保护与软件相关的专有许可证。 Anyways, long story made short... the best way for you to upgrade NPX (which means upgrading NPM, which means you need to upgrade Node.js), is to install the latest version of Node.js, go into the directory, and create symbolic links for npm , node , npx , in your /usr/bin directory and then upgrade eslint (globally) to version v8.18.0 .总之,长话短说……升级NPX最好的方法(就是升级NPM,也就是升级Node.js),就是安装最新版本的Node.js,进入目录,并在/usr/bin目录中为npmnode 、 npx 创建符号链接,然后将npx (全局)升级到v8.18.0版本。 You may also need to create a symbolic link for ESLint.您可能还需要为 ESLint 创建符号链接。




On a final note, just to point out somthing.最后一点,只是为了指出一些事情。 You notice your ESLint version your package.json file is v8.18.0 ?你注意到你的 ESLint 版本你的package.json文件是v8.18.0吗? and the version in the error you are getting is v8.1.0 ?你得到的错误版本是v8.1.0吗?

That is because your local & global eslint installs are different versions of eslint.那是因为您的本地和全球 eslint 安装是不同版本的 eslint。 You should try to always keep everything the same version.您应该尝试始终使所有内容保持相同的版本。

Right now your system is trying to execute npx eslint src as if src is a path, but one everything is updated, you should have the software needed, for eslint & npm to know that its an ESLint command your trying to execute, not a path.现在您的系统正在尝试执行npx eslint src ,就好像src是一条路径一样,但是一切都已更新,您应该拥有所需的软件,以便 eslint 和 npm 知道它是您尝试执行的 ESLint 命令,而不是路径.

我认为你应该在 tsconfig.ts 文件中有这个属性:

"baseUrl": "."

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:找不到与模式“'./src/views/{tokens,atoms,molecules,organisms}/**/*.scss'”匹配的文件 - Error: No files matching the pattern "'./src/views/{tokens,atoms,molecules,organisms}/**/*.scss'" were found npx 没有在反应中创建公共和 src 文件夹 - npx not creating public and src folders in react eslint:无法解析模块“src/interfaces”的路径 - eslint: Unable to resolve path to module 'src/interfaces' npx create-react-app 不生成 public 和 src 文件夹 - npx create-react-app not generating public and src folder 无法使用 npx create-react-app my-app 创建 src 和公共文件夹 - Not able to create src and public folder using npx create-react-app my-app 找不到 npx 命令。 对于 reactJS - npx command not found. For reactJS NPX create-react-app 找不到 @typescript-eslint/experimental-utils@2.19.1 的匹配版本 - NPX create-react-app cannot find a matching version for @typescript-eslint/experimental-utils@2.19.1 npx create-react-app 未在 src forlder 中创建 servicework.js 文件 - npx create-react-app is not creating servicework.js file in src forlder 没有找到匹配的文件...。 (ReactJS) - No matching files ... were found. (ReactJS) [eslint] src\App.js 第 2:8 行中的 React js 错误警告:'person' 已定义但从未使用过 - React js error WARNING in [eslint] src\App.js Line 2:8: 'person' is defined but never used
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM