Cannot find module 'rxjs/subject/BehaviorSubject'

33,073
import {BehaviorSubject} from 'rxjs/BehaviorSubject';

rxjs 6.x

import {BehaviorSubject} from 'rxjs';

See also

Share:
33,073
Hongbo Miao
Author by

Hongbo Miao

https://www.hongbomiao.com

Updated on July 21, 2020

Comments

  • Hongbo Miao
    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
    Hongbo Miao about 8 years
    Thanks, but now it shows: ORIGINAL EXCEPTION: ReferenceError: BehaviorSubject is not defined, actually I am quite confused now which way is recommended now..
  • Hongbo Miao
    Hongbo Miao about 8 years
    One more question. Is it because the new beta version, so the import way changed? thanks
  • Günter Zöchbauer
    Günter Zöchbauer about 8 years
    What was the last version you used? I'm not aware of related changes but it would be easy to check.
  • Hongbo Miao
    Hongbo Miao about 8 years
    I think it is Angular2 beta 12, RxJS 5 (but not sure which beta version).
  • Günter Zöchbauer
    Günter Zöchbauer about 8 years
    I'll check a bit later, have to leave for now.
  • Günter Zöchbauer
    Günter Zöchbauer about 8 years
    Works the same for me in beta.12
  • Eric Nelson
    Eric Nelson almost 6 years
    If 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
    ryanm almost 6 years
    rxjs 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
    ryanm almost 6 years
    rxjs 6.x looks like import {BehaviorSubject} from 'rxjs';, more details at stackoverflow.com/a/49665105/3232832