I've been looking all over but none of the solutions I've found have helped. All I want to be able to do is
npm install websocket
Most posts I've found on this suggest people are missing make, gcc, g++, or python, but I have all of these. My python is v2.7.6.
To work around the above npm failing I've made it as far as,
sudo npm --websocket:verbose --nodedir=/home/ubuntu/node install -g websocket
But when I try I get:
ubuntu@ip-172-31-20-33:~$ sudo npm --websocket:verbose --nodedir=/home/ubuntu/node install -g websocket
> websocket@1.0.8 install /usr/local/lib/node_modules/websocket
> node install.js
[websocket v1.0.8] Attempting to compile native extensions.
child_process: customFds option is deprecated, use stdio instead.
make: Entering directory `/usr/local/lib/node_modules/websocket/build'
CXX(target) Release/obj.target/validation/src/validation.o
../src/validation.cc:117:34: error: ‘Arguments’ does not name a type
static Handle<Value> New(const Arguments& args)
^
../src/validation.cc:117:45: error: ISO C++ forbids declaration of ‘args’ with no type [-fpermissive]
static Handle<Value> New(const Arguments& args)
^
../src/validation.cc:125:42: error: ‘Arguments’ does not name a type
static Handle<Value> IsValidUTF8(const Arguments& args)
^
../src/validation.cc:125:53: error: ISO C++ forbids declaration of ‘args’ with no type [-fpermissive]
static Handle<Value> IsValidUTF8(const Arguments& args)
^
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h: In static member function ‘static void Validation::Initialize(v8::Handle<v8::Object>)’:
/home/ubuntu/node/deps/v8/include/v8.h:816:13: error: ‘v8::HandleScope::HandleScope()’ is protected
V8_INLINE HandleScope() {}
^
../src/validation.cc:108:17: error: within this context
HandleScope scope;
^
../src/validation.cc:109:58: error: no matching function for call to ‘v8::FunctionTemplate::New(v8::Handle<v8::Value> (&)(const int&))’
Local<FunctionTemplate> t = FunctionTemplate::New(New);
^
../src/validation.cc:109:58: note: candidate is:
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h:3434:34: note: static v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate*, v8::FunctionCallback, v8::Handle<v8::Value>, v8::Handle<v8::Signature>, int)
static Local<FunctionTemplate> New(
^
/home/ubuntu/node/deps/v8/include/v8.h:3434:34: note: no known conversion for argument 1 from ‘v8::Handle<v8::Value>(const int&)’ to ‘v8::Isolate*’
../src/validation.cc:111:77: error: no matching function for call to ‘NODE_SET_METHOD(v8::Local<v8::Function>, const char [12], v8::Handle<v8::Value> (&)(const int&))’
NODE_SET_METHOD(t->GetFunction(), "isValidUTF8", Validation::IsValidUTF8);
^
../src/validation.cc:111:77: note: candidate is:
In file included from ../src/validation.cc:9:0:
/home/ubuntu/node/src/node.h:211:13: note: template<class TypeName> void node::NODE_SET_METHOD(const TypeName&, const char*, v8::FunctionCallback)
inline void NODE_SET_METHOD(const TypeName& recv,
^
/home/ubuntu/node/src/node.h:211:13: note: template argument deduction/substitution failed:
../src/validation.cc:111:77: note: cannot convert ‘Validation::IsValidUTF8’ (type ‘v8::Handle<v8::Value>(const int&)’) to type ‘v8::FunctionCallback {aka void (*)(const v8::FunctionCallbackInfo<v8::Value>&)}’
NODE_SET_METHOD(t->GetFunction(), "isValidUTF8", Validation::IsValidUTF8);
^
../src/validation.cc:112:17: error: ‘NewSymbol’ is not a member of ‘v8::String’
target->Set(String::NewSymbol("Validation"), t->GetFunction());
^
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h: In static member function ‘static v8::Handle<v8::Value> Validation::New(const int&)’:
/home/ubuntu/node/deps/v8/include/v8.h:816:13: error: ‘v8::HandleScope::HandleScope()’ is protected
V8_INLINE HandleScope() {}
^
../src/validation.cc:119:17: error: within this context
HandleScope scope;
^
../src/validation.cc:121:27: error: request for member ‘This’ in ‘args’, which is of non-class type ‘const int’
validation->Wrap(args.This());
^
../src/validation.cc:122:17: error: request for member ‘This’ in ‘args’, which is of non-class type ‘const int’
return args.This();
^
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h: In static member function ‘static v8::Handle<v8::Value> Validation::IsValidUTF8(const int&)’:
/home/ubuntu/node/deps/v8/include/v8.h:816:13: error: ‘v8::HandleScope::HandleScope()’ is protected
V8_INLINE HandleScope() {}
^
../src/validation.cc:127:17: error: within this context
HandleScope scope;
^
../src/validation.cc:128:36: error: invalid types ‘const int[int]’ for array subscript
if (!Buffer::HasInstance(args[0])) {
^
../src/validation.cc:129:46: error: ‘New’ is not a member of ‘v8::String’
return ThrowException(Exception::Error(String::New("First argument needs to be a buffer")));
^
../src/validation.cc:129:97: error: ‘ThrowException’ was not declared in this scope
return ThrowException(Exception::Error(String::New("First argument needs to be a buffer")));
^
../src/validation.cc:131:38: error: invalid types ‘const int[int]’ for array subscript
Local<Object> buffer_obj = args[0]->ToObject();
^
../src/validation.cc:134:67: error: ‘class v8::HandleScope’ has no member named ‘Close’
return is_valid_utf8(buffer_length, buffer_data) == 1 ? scope.Close(True()) : scope.Close(False());
^
../src/validation.cc:134:78: error: too few arguments to function ‘v8::Handle<v8::Boolean> v8::True(v8::Isolate*)’
return is_valid_utf8(buffer_length, buffer_data) == 1 ? scope.Close(True()) : scope.Close(False());
^
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h:6526:17: note: declared here
Handle<Boolean> True(Isolate* isolate) {
^
../src/validation.cc:134:89: error: ‘class v8::HandleScope’ has no member named ‘Close’
return is_valid_utf8(buffer_length, buffer_data) == 1 ? scope.Close(True()) : scope.Close(False());
^
../src/validation.cc:134:101: error: too few arguments to function ‘v8::Handle<v8::Boolean> v8::False(v8::Isolate*)’
return is_valid_utf8(buffer_length, buffer_data) == 1 ? scope.Close(True()) : scope.Close(False());
^
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h:6535:17: note: declared here
Handle<Boolean> False(Isolate* isolate) {
^
/home/ubuntu/node/deps/v8/include/v8.h: In function ‘void init(v8::Handle<v8::Object>)’:
/home/ubuntu/node/deps/v8/include/v8.h:816:13: error: ‘v8::HandleScope::HandleScope()’ is protected
V8_INLINE HandleScope() {}
^
../src/validation.cc:140:15: error: within this context
HandleScope scope;
^
make: *** [Release/obj.target/validation/src/validation.o] Error 1
make: Leaving directory `/usr/local/lib/node_modules/websocket/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.emit (events.js:110:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1059:12)
gyp ERR! System Linux 3.13.0-36-generic
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/websocket
gyp ERR! node -v v0.13.0-pre
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok
[websocket v1.0.8]
Native code compile failed!!
Please note that this module DOES NOT REQUIRE the native components
and will still work without them, though not quite as efficiently.
On Windows, native extensions require Visual Studio and Python.
On Unix, native extensions require Python, make and a C++ compiler.
Start npm with --websocket:verbose to show compilation output (if any).
websocket@1.0.8 /usr/local/lib/node_modules/websocket
Anybody know what's going on?
I notice it's been awhile since websocket-node has been updated. I'm wondering if websocket-node simply isn't compatible with node v0.13.0-pre? Should I even be using v0.13.0-pre?
Ultimately I just want to be able to run http/https & ws/wss from the same node.js instance on the same port. websocket-node seems able to handle fine, but isn't clear how to do with the ws module (which works fine for just doing plain old ws).
Any pointers on how to use ws would be just as good as figuring out what's wrong with websocket.
It appears that the problem was indeed an incompatibility with node v0.13.0-pre. I got the source and installed node v0.10.32 and then did
sudo npm --websocket:verbose --nodedir=/home/ubuntu/node-v0.10.32 install -g websocket
and websocket installed correctly.
I had to manually install node-gyp to make some other npm install work properly. I can't recall whether I had to install node-gyp globally or not but...
npm install -g node-gyp
npm install websocket
Instead of relying on Node.js to do the termination, you can use a reverse-proxy. This is in many ways a simpler setup. If you're using Nginx, a configuration file like the following is what you want:
server {
listen 443 ssl;
server_name <hostname>;
ssl_certificate <path>/<name>.crt;
ssl_certificate_key <path>/<name>.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:80;
}
}
This will open port 443, do SSL termination on traffic to that port, and then forward the traffic to port 80 (where your Node.js app will be running).