admin管理员组文章数量:1307403
I have only this in my server file and the error appear:
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 9000 });
wss.broadcast = function broadcast(data) {
wss.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(data);
}
});
};
wss.on('connection', function connection(ws) {
ws.on('message', function ining(data) {
wss.broadcast(data);
});
});
The Terminal shows this error:
/home/mgmaip/server/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> (/home/mgmaip/server/node_modules/ws/lib/PerMessageDeflate.js:8:24)
at Module._pile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/mgmaip/server/node_modules/ws/lib/WebSocket.js:16:27)
at Module._pile (module.js:397:26)
I have the last version of node, someone knows what happens? Thanks!
I have only this in my server file and the error appear:
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 9000 });
wss.broadcast = function broadcast(data) {
wss.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(data);
}
});
};
wss.on('connection', function connection(ws) {
ws.on('message', function ining(data) {
wss.broadcast(data);
});
});
The Terminal shows this error:
/home/mgmaip/server/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> (/home/mgmaip/server/node_modules/ws/lib/PerMessageDeflate.js:8:24)
at Module._pile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/mgmaip/server/node_modules/ws/lib/WebSocket.js:16:27)
at Module._pile (module.js:397:26)
I have the last version of node, someone knows what happens? Thanks!
Share Improve this question asked Feb 19, 2017 at 19:22 mgm793mgm793 2,06618 silver badges26 bronze badges1 Answer
Reset to default 10From this issue, ws
v2 doesn't work with node < 4.5.0 (see patibility below). You can either upgrade to a newer version of node or use previous version of ws ws@1
:
npm install ws@1
After conducting some test, here is a list of patibility, ws@2
works between node v4.5.0
& v4.7.3
and from v5.10.0
:
| node version | ws@2 working |
|--------------|--------------|
| v4.4.7 | |
| v4.5.0 | OK |
| v4.6.0 | OK |
| v4.6.1 | OK |
| v4.6.2 | OK |
| v4.7.0 | OK |
| v4.7.1 | OK |
| v4.7.2 | OK |
| v4.7.3 | OK |
| v5.0.0 | |
| v5.1.0 | |
| v5.1.1 | |
| v5.2.0 | |
| v5.3.0 | |
| v5.4.0 | |
| v5.4.1 | |
| v5.5.0 | |
| v5.6.0 | |
| v5.7.0 | |
| v5.7.1 | |
| v5.8.0 | |
| v5.9.0 | |
| v5.9.1 | |
| v5.10.0 | OK |
| v5.10.1 | OK |
| v5.11.0 | OK |
| v5.11.1 | OK |
| v5.12.0 | OK |
本文标签: javascriptquotTypeError this is not a typed arraywithquot WSjs in NodejsStack Overflow
版权声明:本文标题:javascript - "TypeError: this is not a typed array.with" WS.js in Node.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741836170a2400227.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论