0

This my code HTML file

<!DOCTYPE html>
<html>
<head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
</head>
<body>
    <div id="app"></div>
    <script src="../node_modules/rxjs/bundles/rxjs.umd.min.js"></script>
    <script src="./Test.js"></script>
</body>
</html>

This my code Js file

const stream = Rx.Observable.create(...);

When I want to use Rx I get Error.

Uncaught ReferenceError: Rx is not defined

I can’t understand what the problem is.

Edgar
  • 6,022
  • 8
  • 33
  • 66

1 Answers1

2

In RxJs 6 the object is called rxjs

const stream = rxjs.Observable.create(...);

or

const { Observable } = rxjs;
const stream = Observable.create(...);

If you are using npm then you need to import the parts you need as the main thing about RxJs 6 over 5 is that it is tree shakeable

import { Observable } from 'rxjs';

const stream = Observable.create(...);
Adrian Brand
  • 20,384
  • 4
  • 39
  • 60
  • 1
    now I get the error Test.js: 1 Uncaught SyntaxError: Cannot use import statement outside a module – Edgar Oct 05 '19 at 04:07
  • If you are including the full package rxjs.umd.min.js then use one of the first two methods, the import method is if you are using a build system like webpack. – Adrian Brand Oct 05 '19 at 07:35