簡體   English   中英

Atom & eslint:找不到模塊 'eslint-config-react-app'

[英]Atom & eslint: Cannot find module 'eslint-config-react-app'

由於我在我的 create-react-app 項目中重新安裝了我的 NPM 依賴項,因此 Atom 的 eslint 在每個文件的頂部都給了我這個錯誤:

Error while running ESLint: Cannot find module 'eslint-config-react-app'.

雖然react-scripts的 eslint 不會引發任何警告或錯誤。 順便說一句,package eslint-config-react-app安裝node_modules中。 我嘗試重新安裝 linter-eslint、atom、NPM 依賴項等。沒有任何效果。

有人有想法嗎?

這是我的.eslintrc:

{
  "extends": "react-app",
  "rules": {
    "jsx-a11y/anchor-is-valid": 0,
    "react/jsx-no-comment-textnodes": 0,
    "no-unused-vars": ["warn", {
      args: "all",
      ignoreRestSiblings: false,
      argsIgnorePattern: "^_$"
    }]
  }
}

編輯:我不知道為什么,但突然之間,錯誤發生了變化,現在它是每個 js 文件頂部的錯誤:

Error while running ESLint: Invalid regular expression flags

編輯 2

給定的解決方案都不適用於我的情況。 linter-eslint的問題沒有解決。 但我現在找到了一種解決方法:使用fast-eslint而不是linter-eslint 工作得很好。

對於嘗試此操作的其他人,一種解決方案是全局安裝 eslint-config-react-app 及其所有對等部門。 此刻,就是:

參考https://github.com/facebook/create-react-app/issues/3633#issuecomment-361485857

npm i -g babel-eslint@^7.2.3 eslint@^4.1.1 eslint-plugin-flowtype@^2.34.1 eslint-plugin-import@^2.6.0 eslint-plugin-jsx-a11y@^5.1.1 eslint-plugin-react@^7.1.0

由於您提到問題是在您重新安裝 npm 模塊后出現的,它可能與 npm 依賴解析有關。 因此,您可能有同一個模塊的多個版本,而 atom 可能會使用錯誤的版本。

  1. 根據Displaying Lint Output in the Editor檢查您的 react-scripts 版本是否為 0.2.0 或更高

  2. 從 package.json 中刪除所有與eslint相關的依賴package.json

    這意味着刪除babel-eslinteslinteslint-plugin-flowtypeeslint-plugin-importeslint-plugin-jsx-a11yeslint-plugin-react

    Create react app 會在后台安裝所有 linting 依賴項,因此您不應手動安裝它們。

  3. 刪除所有與全局eslint相關的依賴項。

    通常,您不需要使用全局安裝的 eslint 依賴項,因為您的每個項目中可能有不同的 eslint 版本。

然后,最新版本的linter-eslint應該使用項目中 node_modules 下的正確node_modules依賴項。

更新:根據您的評論和編輯的問題,我嘗試使用 CRA 重現此內容,替換package.json中的依賴項,重新安裝並添加以下.eslintrc

請注意,我在"no-unused-vars" "

{
  "extends": "react-app",
  "rules": {
    "jsx-a11y/anchor-is-valid": 0,
    "react/jsx-no-comment-textnodes": 0,
    "no-unused-vars": ["warn", {
      "args": "all",
      "ignoreRestSiblings": false,
      "argsIgnorePattern": "^_$"
    }]
  }
}

完成所有這些后,我無法重現該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM