Rxjs: Rx has no default export

Created on 26 Oct 2016  路  16Comments  路  Source: ReactiveX/rxjs

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?

question

Most helpful comment

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 [email protected]
./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.

All 16 comments

Bare with me please, I'm having troubling understanding. Can you elaborate? Running npm install rxjs in a directory that contains a valid package.json for an app seems to work fine. Where I get pretty confused is

so I created my own package.json file like the following

Why did you need to create a package.json with the name @reactivex/rxjs? Your package.json should be _your_ app's, not RxJS's.

I get the error message, that Rx has no default export.

What is the actual error message and what tool is emitting it? node? TypeScript? webpack? Can you provide details on what build environment you're using?

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.

Thanks for your reply. I am using Visual Studio Code - sorry, I forgot this. In the first place I thought, that the package.json shouldn't even be necessary to exist in an empty directory where I want to download rx/js. But whenever I try to "npm install rxjs" nothing is downloaded, so I created my own package.json (this might have been the wrong approach, but I do not know npm very well)

import * as Rx from 'rxjs';

Works fine for me! But then I would have to import anything...

Would you mind share bit more detail? are you referring to import necessary operator such as

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

Observable.of(1,2,3).map(x => x + '!!!'); // etc

at https://github.com/ReactiveX/rxjs#es6-via-npm ?

I just tried whats in the tutorial:

To import the entire core set of functionality:

import Rx from 'rxjs/Rx';

Rx.Observable.of(1,2,3)

Here "Rx" is not the default export

Sorry, so you're saying import * as Rx from works and import Rx doesn't work?

@web265p3 What is the actual, full error message and what tool is emitting it? node? TypeScript? webpack? Can you provide details on what build environment you're using?

I am using Visual Studio code and installed TypeScript. What kwonoj is saying is right. Exactly that happens.

@web265p3 , I'd like to provide additional details as much I can but I'm pretty much out of idea as @jayphelps does. Currently there is barely no information we can guess about your project setup. If you have minimum repo can reproduce current behavior, it'd appreciate to share it to able to try. Each transpiler / bundler setup might have different configurations.

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 [email protected]
./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.

That is enough for me actually ;)

@ds82, using the wildcard import fixed it for me. I'm using typescript 2, node js (4.3.2), rxjs 5.0.3 and typings es6shim installed as per the docs. Thanks!

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

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

@Neutrino-Sunset hey, thanks for the heads up. Could you send a PR that corrects it?

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

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dooreelko picture dooreelko  路  3Comments

chalin picture chalin  路  4Comments

peterbakonyi05 picture peterbakonyi05  路  4Comments

LittleFox94 picture LittleFox94  路  3Comments

haf picture haf  路  3Comments