With the widespread support for JavaScript modules in all modern browsers, I am experimenting with importing code directly in the browser using import
. Utilizing unpkg.com for npm modules and exploring the jspm project that converts npm modules into a format compatible with browsers.
However, I am encountering challenges, particularly with RxJS. RxJS version 6 suggests importing constructors and operators as follows:
import { Observable, Subject, ReplaySubject, from, of, range } from 'rxjs';
import { map, filter, switchMap } from 'rxjs/operators';
Attempting to do this in the browser results in errors like:
Uncaught SyntaxError: The requested module '' does not provide an export named 'map'
To work around this, I can import the entire rxjs
module and extract what is necessary:
import rxjs from 'https://dev.jspm.io/rxjs@6';
const { Observable } = rxjs;
import operators from 'https://dev.jspm.io/rxjs@6/operators';
const { map } = operators;
Nonetheless, this goes against the effort by the Rx team to optimize bundle size.
This issue extends beyond just RxJS. What steps should we take moving forward to achieve our goal of seamlessly transitioning our development javascript imports in the browser to meet bundler requirements?