Failed to install socket.io by npm

2019-06-01 11:16发布

问题:

I have nodejs v0.12.2 installed, and the Visual C++ express 2010 and Visual Studio 2010 Service Pack 1. When I ran npm install -g socket.io, i got thousands line error.

something like below, anyone could help to research and fix this error?

D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\node_modules\eng
ine.io-client\node_modules\ws>if not defined npm_config_node_gyp (node "C:\Program Files (x86)\nodej
s\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (r
ebuild)
Building the projects in this solution one at a time. To enable parallel build, please add the "/m"
switch.
  bufferutil.cc
D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\node_modules\en
gine.io-client\node_modules\ws\node_modules\nan\nan.h(213): error C2039: 'ThrowException' : is not
a member of 'v8' [D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-clie
nt\node_modules\engine.io-client\node_modules\ws\build\bufferutil.vcxproj]
D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\node_modules\en
gine.io-client\node_modules\ws\node_modules\nan\nan.h(213): error C2039: 'New' : is not a member of
 'v8::String' [D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\
node_modules\engine.io-client\node_modules\ws\build\bufferutil.vcxproj]
          C:\Users\czhu\.node-gyp\0.12.2\deps\v8\include\v8.h(1599) : see declaration of 'v8::Strin
  g'
D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\node_modules\en
gine.io-client\node_modules\ws\node_modules\nan\nan.h(213): error C3861: 'ThrowException': identifi
er not found [D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\n
ode_modules\engine.io-client\node_modules\ws\build\bufferutil.vcxproj]
D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\node_modules\en
gine.io-client\node_modules\ws\node_modules\nan\nan.h(213): error C3861: 'New': identifier not foun
d [D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\node_modules
\engine.io-client\node_modules\ws\build\bufferutil.vcxproj]
D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\node_modules\en
gine.io-client\node_modules\ws\node_modules\nan\nan.h(218): error C2039: 'ThrowException' : is not
a member of 'v8' [D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-clie
nt\node_modules\engine.io-client\node_modules\ws\build\bufferutil.vcxproj]
D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\node_modules\en
gine.io-client\node_modules\ws\node_modules\nan\nan.h(218): error C3861: 'ThrowException': identifi
er not found [D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\n
ode_modules\engine.io-client\node_modules\ws\build\bufferutil.vcxproj]
D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\node_modules\en
gine.io-client\node_modules\ws\node_modules\nan\nan.h(222): error C2039: 'New' : is not a member of
 'v8::String' [D:\GitProjects\almwplus\client\node_modules\socket.io\node_modules\socket.io-client\
node_modules\engine.io-client\node_modules\ws\build\bufferutil.vcxproj]

回答1:

I hit the same problem, and it looks to me like a problem with the version of ws that engine.io-client installs. Moving to a newer version of ws solved the problem for me. One way to get that is to install the latest (unpublished) version of socket.io from github:

npm install -g automattic/socket.io