deepstreamIO / deepstream.io-client-js

The Browser / Node.js Client for deepstream.io
Other
294 stars 109 forks source link

"NodeWebSocket is not a constructor" when executing node application #357

Closed ennetech closed 7 years ago

ennetech commented 7 years ago

Hello! I was integrating deepstream in a library i am writing but i encounter the error in the console.

This is the minimum amount of code that is needed to trigger the problem: index.js

var deepstream = require('deepstream.io-client-js')
const client = deepstream('localhost').login();

problem:

# node ./dist/main.js
        this._endpoint = BrowserWebSocket ? new BrowserWebSocket(this._url) : new NodeWebSocket(this._url, this._options.nodeSocketOptions);
                                                                              ^

TypeError: NodeWebSocket is not a constructor
    at Connection._createEndpoint (C:\Users\ricca\Desktop\deepstream\zap\dist\main.js:2549:72)
    at new Connection (C:\Users\ricca\Desktop\deepstream\zap\dist\main.js:2443:7)
    at new Client (C:\Users\ricca\Desktop\deepstream\zap\dist\main.js:1780:22)
    at createDeepstream (C:\Users\ricca\Desktop\deepstream\zap\dist\main.js:1997:10)
    at Object.<anonymous> (C:\Users\ricca\Desktop\deepstream\zap\dist\main.js:1739:14)
    at __webpack_require__ (C:\Users\ricca\Desktop\deepstream\zap\dist\main.js:20:30)
    at Object.<anonymous> (C:\Users\ricca\Desktop\deepstream\zap\dist\main.js:6614:18)
    at __webpack_require__ (C:\Users\ricca\Desktop\deepstream\zap\dist\main.js:20:30)
    at exports.CONNECTION_STATE (C:\Users\ricca\Desktop\deepstream\zap\dist\main.js:66:18)
    at Object.<anonymous> (C:\Users\ricca\Desktop\deepstream\zap\dist\main.js:69:10)

webpack.config.js

var path = require('path')
module.exports = {
    entry: {
        main: [path.resolve(__dirname, 'src/index.js')]
    },
    output: {
        filename: "./dist/[name].js"
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                query: {
                    "presets": [
                        "es2015"
                    ],
                    "plugins": [
                    ],
                }
            }
        ]
    }
}

in compiled file i could find:

...
NodeWebSocket = __webpack_require__(34),
...
/* 34 */
/***/ (function(module, exports) {

/* (ignored) */

/***/ }),
...

Any suggestion? thank you!

yasserf commented 7 years ago

Can you try running this with a slightly older version of the client? I believe the last client updated the WebSocket dependency which has some backwards compatibility.

ennetech commented 7 years ago

Maybe if i avoid using a browser tool to pack for node i could avoid opening stupid issues :)

BTW: There is a bug on 2.1.2, on a incoming event a "ReferenceError: processed is not defined" is raised, I saw it's already fixed on master: https://github.com/deepstreamIO/deepstream.io-client-js/commit/d3ea151d59aa7d52e20c23af71b174cdb0956613#diff-6a60238bc33d426a5b06f3d61977ab30 src/event/event-handler.js @ ~175

When is the next release scheduled?

yasserf commented 7 years ago

ASAP really. I just need to get the open PRs in. Was hoping for today but didn't find the time unfortunately, my guess is Wednesday.