Solvedrxjs Rx has no default export

I just followed the easy steps to install the package. When I type "npm install rxjs" nothing is created, so I created my own package.json file like the following:

{
  "name": "@reactivex/rxjs",
  "version": "5.0.0-rc.1",
  "description": "Reactive Extensions for modern JavaScript",
  "main": "index.js"
}

After running "npm install rxjs" again I get the node_modules folder with everything inside. But when I want to import "import Rx from 'rxjs/Rx';" I get the error message, that Rx has no default export.
Actually there is not a lot to do wrong here, but I'm stuck. Any proposals?

17 Answers

✔️Accepted Answer

Let me help a bit (because I just had the same issue and this thread helped me):

mkdir rxjs-typescript-test; cd rxjs-typescript-test
npm i typescript rxjs@5.0.0-rc.1
./node_modules/.bin/tsc --init
echo "import Rx from 'rxjs/Rx';" > index.ts // <-- this line is from your README and @web265p3 refers to it
./node_modules/.bin/tsc index.ts

That emits this error:

index.ts(1,8): error TS1192: Module '"/Users/dsaenger/code/rxjs-typescript-test/node_modules/rxjs/Rx"' has no default export.

Changing import Rx from 'rxjs/Rx'; to import * as Rx from 'rxjs/Rx'; fixes it.

Other Answers:

There is differing implementations on how ES6 default exports are determined when dealing with source which uses CommonJS modules.

One thing that will likely work regardless of env is this:

import * as Rx from 'rxjs';

// or things like

import { Observable } from 'rxjs';

Because it doesn't even try to import a default export.

Once I know what build env you're using, I'll try to reproduce the default export issue and then have a better understanding whether this is an oversight by us or a limitation/misconfiguration of the env.

Fyi, 1 year later, your documentation is still wrong.

http://reactivex.io/rxjs/manual/installation.html

@jayphelps Nope, he couldn't. And neither can I. But fix it, please?

More Issues: