Post

Resolving Blacklisted RxJS Import TSLint Error

When working with Angular and the Angular CLI, one might import an RxJS Observable as:

1
import { Observable } from 'rxjs';

Later, running TSLint reports This import is blacklisted, import a submodule instead.

Quick fix

To fix the error reported by TSLint, simply change

1
import { Observable } from 'rxjs';

to

1
import { Observable } from 'rxjs/Observable';

Now, run TSLint and the error should be gone! However, this change may have created compilation error(s), potentially requiring importing some operators.

Import operators (as necessary)

After making this change, some operators may need to be imported. Here’s how to import map:

1
import 'rxjs/add/operator/map';

Extra

This blacklisted import can be found in tslint.json as:

1
2
3
4
5
{
  "rules": {
    "import-blacklist": [true, "rxjs"]
  }
}
This post is licensed under CC BY 4.0 by the author.