【问题标题】:Eslint 'rxjs/operators' should be listed in the project's dependenciesEslint 'rxjs/operators' 应该列在项目的依赖中
【发布时间】:2021-08-07 17:54:12
【问题描述】:

所以我的文件中有这个导入

import { catchError, finalize } from 'rxjs/operators';

当我运行 eslint 时出现此错误:

 error  'rxjs/operators' should be listed in the project's dependencies. Run 'npm i -S rxjs/operators' to add it  import/no-extraneous-dependencies

我在 package.json 依赖项列表中有 rxjs,但似乎 eslint 认为 'rxjs/operators' 是另一个包。

在我的 eslintrc 文件中,我有这个规则:

"import/no-extraneous-dependencies": [
        "error",
        {
            "devDependencies": ["**/*.test.ts", "**/*.test.tsx"]
        }
    ],

【问题讨论】:

    标签: typescript eslint package.json


    【解决方案1】:

    我遇到了同样的问题并修复了以下问题:this 通过添加

    ...
    "settings": {
       "import/core-modules": ["rxjs/operators"]
    },
    ...
    

    在我的 .eslintrc.json 配置文件中。

    【讨论】:

      【解决方案2】:

      @Wana 的解决方案有效,但您可能会发现这实际上是 eslint-plugin-import 规则的问题。

      如果您将 eslint-plugin-import 更新到 v2.23.4,您可能会发现此问题已修复。包解析算法最近出现了回归。

      npm update eslint-plugin-import
      

      Read more about the issue

      【讨论】:

        猜你喜欢
        • 2017-12-09
        • 1970-01-01
        • 2018-10-29
        • 2021-03-29
        • 2019-04-18
        • 1970-01-01
        • 2021-10-15
        • 2022-06-26
        • 2012-09-17
        相关资源
        最近更新 更多