Cannot find module 'rxjs/subject/BehaviorSubject'
33,073
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
rxjs 6.x
import {BehaviorSubject} from 'rxjs';
See also
- Property 'of' does not exist on type 'typeof Observable
- https://stackoverflow.com/a/49665105/3232832
Comments
-
Hongbo Miao almost 4 years
I am using Angular 2.
When I use either of these two, my program runs well:
import { BehaviorSubject } from 'rxjs/Rx'; import { BehaviorSubject } from 'rxjs';
However, I try to use the following way:
import { BehaviorSubject } from 'rxjs/subject/BehaviorSubject';
But I failed, my browser console shows:
Uncaught Error: Cannot find module 'rxjs/subject/BehaviorSubject'
How can I use third way correctly? Thanks
-
Hongbo Miao about 8 yearsThanks, but now it shows:
ORIGINAL EXCEPTION: ReferenceError: BehaviorSubject is not defined
, actually I am quite confused now which way is recommended now.. -
Hongbo Miao about 8 yearsOne more question. Is it because the new beta version, so the import way changed? thanks
-
Günter Zöchbauer about 8 yearsWhat was the last version you used? I'm not aware of related changes but it would be easy to check.
-
Hongbo Miao about 8 yearsI think it is Angular2 beta 12, RxJS 5 (but not sure which beta version).
-
Günter Zöchbauer about 8 yearsI'll check a bit later, have to leave for now.
-
Günter Zöchbauer about 8 yearsWorks the same for me in beta.12
-
Eric Nelson almost 6 yearsIf you are here because you are trying to use @angular/flex-layout and got errors about BehaviorSubject, try installing @angular/[email protected]. Worked for me.
-
ryanm almost 6 yearsrxjs 6.x looks like
import {BehaviorSubject} from 'rxjs/internal/BehaviorSubject';
This is where it's invaluable to have an IDE like WebStorm/PHPStorm - autocomplete so you can discover import paths like that. -
ryanm almost 6 yearsrxjs 6.x looks like
import {BehaviorSubject} from 'rxjs';
, more details at stackoverflow.com/a/49665105/3232832