سؤال

I simply want to implement

https://github.com/Reactive-Extensions/RxJS

to my node project.

Surely, there is the npm-package available, but I see it less updated, less modules, and uses only min. files, so I want to use rxjs from git sources.

I downloaded RxJS-master and copy the whole files under the Dir to ../myProject/lib/rx/

I see

rx.node.js among those files

var Rx = require('./rx');
require('./rx.aggregates');
require('./rx.binding');
require('./rx.coincidence');
require('./rx.experimental');
require('./rx.joinpatterns');
require('./rx.testing');
require('./rx.time');
module.exports = Rx;

so, my app.js code is like this

var rx = require("./lib/rx/rx.node.js")

function test()
{
    var as = new rx.AsyncSubject()
    setTimeout(function ()
    {
        as.onNext("works!")
        as.onCompleted()
    }, 500)
    return as
}

var a = test().subscribe(function (result)
{
    console.log("Got result: " + result)
})

This gives an error as follows,

.../rx/lib/rx/rx.binding.js:173
    var BehaviorSubject = Rx.BehaviorSubject = (function (_super) {
                          ^
ReferenceError: Rx is not defined
    at .../rx/lib/rx/rx.binding.js:173:27
    at Observable (.../rx/lib/rx/rx.binding.js:14:26)
    at Object.<anonymous> (.../rx/lib/rx/rx.binding.js:18:2)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (.../rx/lib/rx/rx.node.js:3:1)

Process finished with exit code 1

What is wrong?


If I modify rx.node.js to

var Rx = require('./rx');
module.exports = Rx;

The code works as expected, so obviously require - sub modules section does not go well.


Thanks.

هل كانت مفيدة؟

المحلول

Fixed as of the latest build and I removed the bad build in question with this commit

NPM has been updated accordingly to remove 2.1.1 and replaced with a non-broken version.

نصائح أخرى

This looks like a problem with the build that you are running, which I assume is 2.1.1. I had the same problem and the following npm commands fixed it for me.

npm remove rx
npm install rx@2.1.0

EDIT: I see you are using master. Sorry for the confusion. This solution might work for others that are running 2.1.1.

I think you can do this. If this command:

$ which npm
/usr/local/bin/npm

You can do this:

$ npm remove rx
$ npm install -g rx

If you don´t have nothing for "which npm" it can you must to remove node with this issue(the best answer) and reinstall with brew (with MacOS) or your package manager:

$ brew update
$ brew uninstall node
$ brew install node

and it can you must to use this:

$ brew postinstall node 

According to the discussion on this issue.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top