websockets / ws

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot `require('ws')`

vidstige opened this issue · comments

I npm installed 2.0.2 and upon just issuing node -e "require('ws')" ws blows up with the following stacktrace.

I'm using node v4.2.6

/Users/vidstige/src/tumel/node_modules/ws/lib/PerMessageDeflate.js:8
const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
                       ^

TypeError: this is not a typed array.
    at Function.from (native)
    at Object.<anonymous> (/Users/vidstige/src/tumel/node_modules/ws/lib/PerMessageDeflate.js:8:24)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/Users/vidstige/src/tumel/node_modules/ws/lib/WebSocket.js:16:27)
    at Module._compile (module.js:410:26)

Buffer.from() does not work on Node.js < 4.5.0. Is it possible for you to upgrade to a more recent version?

Thanks for quick reply. I rather not, using port install nodejs to install which only has 4.3, but might consider later. I could perhaps also downgrade ws?

Yes, you can use ws@1. It's a shame though as there are a lot of bug fixes in v2. Can I ask why you prefer port over brew? Homebrew has the latest Node.js 4 available at node@4.

$ brew info node@4
node@4: stable 4.7.3 (bottled), HEAD [keg-only]
Platform built on V8 to build network applications
https://nodejs.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/node@4.rb

No, I like ports more. It does have node, but inside another package called node4. But I'll go with that anyway. Thanks fro your help! :)