Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't Resolve rxjs

Failed to compile.

./src/app/hero.service.ts Module not found: Error: Can't resolve 'rxjs/Observable/of' in 'C:\Users\Admin\angular\myheroes\src\app'

@ ./src/app/hero.service.ts 13:11-40  @ ./src/app/app.module.ts  @ ./src/main.ts  @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts 

my code for hero.service.ts

import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { of } from 'rxjs/Observable/of'; import { Hero } from './hero'; import { HEROES } from './mock-heroes'; import { MessageService } from './message.service';  @Injectable() export class HeroService {     constructor(private messageService: MessageService) { }    getHeroes(): Observable<Hero[]>    {     // todo: send the message _after_fetching the heroes     this.messageService.add('HeroService: fetched heroes');     return of (HEROES);   } } 
like image 392
Bhavin Avatar asked Jan 16 '18 11:01

Bhavin


People also ask

Can not find module RXJS?

To solve the error "Cannot find module 'rxjs-compat/Observable'", make sure to install the package by opening your terminal in your project's root directory and running the following command: npm i rxjs and restart your IDE and development server. Copied!

What is of operator in RXJS?

The of Operator is a creation Operator. Creation Operators are functions that create an Observable stream from a source. The of Operator will create an Observable that emits a variable amount of values in sequence, followed by a Completion notification.


1 Answers

I got this error because of an older version of rxjs and Angular 6 needs the latest version of rxjs.

This command installs the latest version that is compatible with Angular 6.

npm install --save rxjs-compat 
like image 73
Vedha Peri Avatar answered Oct 04 '22 11:10

Vedha Peri