Eslint 'rxjs/operators' should be listed in the project's dependencies

Viewed 721

So i have this import on my file

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

And when i run eslint i get this error:

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

I have rxjs in the package.json dependencies list, but it seems eslint thinks 'rxjs/operators' is another package instead.

In my eslintrc file, i have this rule:

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

I had the same problem and fixed it following: this by adding

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

in my .eslintrc.json config file.

@Wana's solution works, but you may find that this was in fact an issue with the eslint-plugin-import rule.

If you update eslint-plugin-import to v2.23.4, you may find this is fixed. There was a recent regression in the package resolution algorithm.

npm update eslint-plugin-import

Read more about the issue

Related