The module "/node_modules/rxjs/Rx" does not contain the requested export of 'throwError'

When delving into the Angular documentation, there's mention of a "throwError" class with an import statement that looks like this:

import { Observable, throwError } from 'rxjs';

However, my compiler is having trouble locating this class and is throwing 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'.

Here are some details about my environment:

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 could I be overlooking?

Answer №1

Are you in search of the _throw observable?

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

Latest Update

If you are referring to Angular 6 documentation, it uses rxjs version 6 that includes the throwError function. For Angular 5 (which has rxjs version 5), you should use _throw

Answer №2

My decision to do this was driven by my dislike for words that have _ as the first letter

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

Answer №3

Check out the RxJS documentation here: https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md

If you want to avoid using the keyword "throw", you can use _throw after importing it like this:

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

Another option is to not use the leading underscore in _throw. Here's how:

import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
...
const e = ErrorObservable.create(new Error('Oops!'));
const e2 = new ErrorObservable(new Error('Oops again!'));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Invoke the function once the database information has been retrieved

I am new to Node.js and I am attempting to execute a function after running a select query using the code below: private displayUserInfo(): any { let connect = this.connect(); connect.connect(function(err: any) { if (err) throw err; ...

PDF documentation for React and TypeScript amalgamation

I have been exploring ways to create a PDF documentation for my React/Typescript project, but so far I have not come across any library that specifically generates PDF documentation. Currently, I am using Typedoc to generate the documentation, but unfortu ...

ReactJS Redux Provider fails to accept the store

I'm currently in the process of migrating my redux store from using "createStore" to "configureStore" due to the deprecation of "createStore". I am working with ReactJS 17 and TypeScript, with the following versions of Redux / Redux dependencies: &quo ...

Retrieving coordinates from an API and displaying them on a Google Maps interface

I have a task where I need to retrieve location coordinates from an API and display the area on a Google Map embedded within my webpage using Angular 2. Here is what I have accomplished so far: MapComponent.ts import { Component, OnInit } from '@angu ...

How to toggle tooltip visibility dynamically using Angular 2

I am working with elements within an ngFor loop. Some of these elements have tooltips, while others do not. I am experiencing an issue where when using the code snippet below: <div ngFor="let item of items"> <div [title]="item.title"> Ele ...

Having trouble retrieving the parameter input reference in the sample code for Angular/NGXS

I am currently working on integrating the login functionality described in this guide. @Action(Login) login({ patchState }: StateContext<AuthStateModel>, { payload: { username } }: Login) { return this.authService.login(payload).pipe(tap(( ...

Exploring how to traverse a <router-outlet> within its container

I am attempting to switch the active component within a from its parent. After observing how Ionic achieves this, I believe it should resemble the following (simplified): @Component({ template: '<router-outlet></router-outlet>' } ...

eslint rule prohibiting directly checking numbers

Does eslint have a rule that flags an error for the code snippet below: function parseNumber(numberToCheck: number | undefined) { // I want an error here: !0 is true, so we will get "no number" here if (!numberToCheck) { return "no n ...

Here's a unique version: "Utilizing the onChange event of a MaterialUI Select type TextField to invoke a function."

I am currently working on creating a Select type JTextField using the MaterialUI package. I want to make sure that when the onChange event is triggered, it calls a specific function. To achieve this, I have developed a component called Select, which is es ...

The spyOn function was unable to locate an object to spy on for the start() method

I've been utilizing the angular-cli testing framework for my project. Within one of my components, I decided to include the 'ng2-slim-loading-bar' node module. submit(){ this._slimLoadingBarService.start(() => { }); //perfor ...

How can I limit the scope of Bootstrap CSS to a specific Angular component?

Has anyone successfully isolated Bootstrap's css file to just one Angular component? I've encountered issues when including the file globally in styles.css or in .angular-cli.json, as the global styles affect other components that shouldn't ...

methods for transforming a string into an object

let styleValues = "{ "background-color": "#4a90e2", "padding": 10px }"; JSON.parse(styleValues); The code snippet above triggers the error below: Uncaught SyntaxError: Unexpected token p in JSON at position 46 ...

How to replace/redirect the import statement in TypeScript from { X } to 'Y'

My situation involves an external library known as Y, which was installed using npm and loaded from the node_modules directory. This library is hosted on GitHub and currently being utilized in my project in the following manner: import { X } from 'Y& ...

Modifying the form-data key for file uploads in ng2-file-upload

I have implemented the following code for file upload in Angular 2+: upload() { let inputEl: HTMLInputElement = this.inputEl.nativeElement; let fileCount: number = inputEl.files.length; let formData = new FormData(); if (fileCount > 0) { // a f ...

Ways to integrate angular-calendar (mattlewis92) into an Angular component without using it as a package

We are currently utilizing the angular-calendar (mattlewis92) library. In order to have more precise control over the calendar functionality, we aim to integrate it as an Angular component rather than just a package. Even after including all the necessary ...

The type 'Observable' does not contain the properties found in type 'User'

I am trying to retrieve user data from Firestore, but encountering an error The type 'Observable' is missing the following properties from type 'User': email, emailVerified, uidts(2739) user.service.ts import { Injectable } from &apo ...

Waiting for Subscribe in other method in Angular RxJS

@Component({ selector: 'note-consultant', template: '<div> <div>{{patientInformation}}</div> <textarea #textElemRef></textarea> <button (click)="onSave()">Done</button> </div&g ...

Invoke a function prior to another in Angular

There are 2 methods that I have: private rowClicked: any; onButtonClicked() { console.log(this.rowClicked) // undefined } onRowClicked(event: any) { this.rowClicked = event.data; } My goal is to delete a row in my ag-grid when clicking a butt ...

Is it possible to assign an interface as an argument of an arrow function?

Here is the code I have written: interface ImyInterface { v: number; } class A implements OnInit { ngOnInit() { let myObservable$ = getObs(); myObservable$.subscribe(data => { const foo = data as ImyInterface; ...

There seems to be an issue with the React app where the fetch() response is coming back empty. Strangely enough, when sending

Below is the code for my API call: export async function getTasks(): Promise<Task[]> { if (process.env.NODE_ENV === "test") { return new Promise<Task[]>((resolve) => setTimeout(() => resolve(DefaultTasksArray), 1500) ...