首页 > 解决方案 > Eslint 'rxjs/operators' 应该列在项目的依赖中

问题描述

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

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"]
        }
    ],

标签: typescripteslintpackage.json

解决方案


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

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

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


推荐阅读