Search code examples
javascriptrxjscustom-element

Is there a way to import rxjs into a plain js web custom component?


I'm trying to create web custom components using plain js. I would like to use rxjs and observables to fetch json content from a REST endpoint that I am also creating using python pyramid. However, an error - 'TypeError: global is undefined' - is being thrown when I import rxjs.

import 'https://unpkg.com/@reactivex/rxjs@6.0.0/dist/global/rxjs.umd.js';

also tried:

import 'https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.2/rxjs.umd.js';

I would like to NOT use npm at all.


Solution

  • <script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.2/rxjs.umd.js"></script>
    

    then:

    const { Observable, from } = rxjs;