Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node_modules/rxjs/ BehaviorSubject has no exported member 'BehaviorSubject'

I am working with angular services and I got an error which is caused by BehaviorSubject.

Error

Module '"ng5/node_modules/rxjs/BehaviorSubject"' has no exported member 'BehaviorSubject'.

data.service.ts

import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';

@Injectable()
export class DataService {

  constructor() { }
}
like image 806
x7R5fQ Avatar asked May 28 '18 15:05

x7R5fQ


1 Answers

if you want to import all RxJS just do :

import { BehaviorSubject } from 'rxjs';

If you only need BehaviorSubject :

import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';

EDIT : Explication

On ES6 / TypeScript all import is related to export keyword. If you go on node_modules/rxjs/index.d.ts you will see all exported Class.

This means what ever see as exported on this file can be imported as : import { SomeThing } from 'rxjs';

But, your generated bundle file will inclure all RxJS stuff including unnecessary part of this library.

To avoid that, i recommand you to import from : from 'rxjs/internal/SomeThing' (replace SomeThing by what you need)

For operators, you can find it on from 'rxjs/internal/operators/SomeThing'

like image 105
Yanis-git Avatar answered Nov 20 '22 05:11

Yanis-git