kathikeyan A
kathikeyan A

Reputation: 1877

".../node_modules/rxjs/Rx" has no exported member 'throwError'

Angular documentation speaks about a "throwError" class whose import statement looking like the following

import { Observable, throwError } from 'rxjs';

But my compiler is not able to find the class and is complaining with the following error message

ERROR in src/app/shared/services/myservice.service.ts(3,10): error TS2305: Module '"D:/workspace/dev/MyProject/node_modules/rxjs/Rx"' has no exported member 'throwError'.

Following are my environment details

Angular CLI: 1.6.8
Node: 8.11.1
OS: win32 x64
Angular: 5.2.8
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

@angular/cdk: 5.2.4
@angular/cli: 1.6.8
@angular/material: 5.2.4
@angular/service-worker: 1.0.0-beta.16
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.4.5
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.8
@schematics/angular: 0.1.17
typescript: 2.4.2
webpack: 3.10.0

What am I missing?

Upvotes: 10

Views: 11989

Answers (3)

user8604852
user8604852

Reputation: 1

I did this since I don't like using words that start with _

import { _throw as throwError } from 'rxjs/observable/throw';

Upvotes: 8

Evgeniy Malyutin
Evgeniy Malyutin

Reputation: 1387

Are you looking for the _throw observable?

import {_throw} from 'rxjs/observable/throw';

update

You were looking at Angular 6 docs which includes rxjs version 6 that contains throwError function. For Angular 5 (includes rxjs 5) use _throw

Upvotes: 18

Basavaraj Bhusani
Basavaraj Bhusani

Reputation: 5683

There is RxJS documentation. Link -> https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md

Because throw is a key word you could use _throw after import { _throw } from 'rxjs/observable/throw'.

Alternatively, if you don't want to use leading _ in _throw, You can do as follows:

import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
...
const e = ErrorObservable.create(new Error('My bad'));
const e2 = new ErrorObservable(new Error('My bad too'));

Upvotes: 0

Related Questions