admin管理员组

文章数量:1432222

Getting this error when validating data received from the client through socket.io.

C:\Users\Rayce\Documents\SENG513\node-js-getting-started\node_modules\socket.io\node_modules\ws\lib\Receiver.js:532
6:23:55 PM web.1 |              if (!Validation.isValidUTF8(messageBuffer)) {
6:23:55 PM web.1 |                             ^
6:23:55 PM web.1 |  TypeError: Cannot read property 'isValidUTF8' of undefined
6:23:55 PM web.1 |      at C:\Users\Rayce\Documents\SENG513\node-js-getting-started\node_modules\socket.io\node_modules\ws\lib\Receiver.js:532:28
6:23:55 PM web.1 |      at C:\Users\Rayce\Documents\SENG513\node-js-getting-started\node_modules\socket.io\node_modules\ws\lib\Receiver.js:368:7
6:23:55 PM web.1 |      at C:\Users\Rayce\Documents\SENG513\node-js-getting-started\node_modules\socket.io\node_modules\ws\lib\PerMessageDeflate.js:249:5
6:23:55 PM web.1 |      at afterWrite (_stream_writable.js:355:3)
6:23:55 PM web.1 |      at onwrite (_stream_writable.js:346:7)
6:23:55 PM web.1 |      at WritableState.onwrite (_stream_writable.js:89:5)
6:23:55 PM web.1 |      at afterTransform (_stream_transform.js:79:3)
6:23:55 PM web.1 |      at TransformState.afterTransform (_stream_transform.js:54:12)
6:23:55 PM web.1 |      at Zlib.callback (zlib.js:613:5)
[DONE] Killing all processes with signal  null
6:23:55 PM web.1 Exited with exit code 1

Editing out this section of code in Receiver.js,

if (!Validation.isValidUTF8(messageBuffer)) {
  self.error('invalid utf8 sequence', 1007);
  return;
}

stops the error from occuring but I would prefer a better solution as I'd like to use NPM and can't be bothered to redo this every time an update occurs.

I have also tried installing utf-8-validate into the node_modules folder of socket.io with no success

Getting this error when validating data received from the client through socket.io.

C:\Users\Rayce\Documents\SENG513\node-js-getting-started\node_modules\socket.io\node_modules\ws\lib\Receiver.js:532
6:23:55 PM web.1 |              if (!Validation.isValidUTF8(messageBuffer)) {
6:23:55 PM web.1 |                             ^
6:23:55 PM web.1 |  TypeError: Cannot read property 'isValidUTF8' of undefined
6:23:55 PM web.1 |      at C:\Users\Rayce\Documents\SENG513\node-js-getting-started\node_modules\socket.io\node_modules\ws\lib\Receiver.js:532:28
6:23:55 PM web.1 |      at C:\Users\Rayce\Documents\SENG513\node-js-getting-started\node_modules\socket.io\node_modules\ws\lib\Receiver.js:368:7
6:23:55 PM web.1 |      at C:\Users\Rayce\Documents\SENG513\node-js-getting-started\node_modules\socket.io\node_modules\ws\lib\PerMessageDeflate.js:249:5
6:23:55 PM web.1 |      at afterWrite (_stream_writable.js:355:3)
6:23:55 PM web.1 |      at onwrite (_stream_writable.js:346:7)
6:23:55 PM web.1 |      at WritableState.onwrite (_stream_writable.js:89:5)
6:23:55 PM web.1 |      at afterTransform (_stream_transform.js:79:3)
6:23:55 PM web.1 |      at TransformState.afterTransform (_stream_transform.js:54:12)
6:23:55 PM web.1 |      at Zlib.callback (zlib.js:613:5)
[DONE] Killing all processes with signal  null
6:23:55 PM web.1 Exited with exit code 1

Editing out this section of code in Receiver.js,

if (!Validation.isValidUTF8(messageBuffer)) {
  self.error('invalid utf8 sequence', 1007);
  return;
}

stops the error from occuring but I would prefer a better solution as I'd like to use NPM and can't be bothered to redo this every time an update occurs.

I have also tried installing utf-8-validate into the node_modules folder of socket.io with no success

Share Improve this question edited Feb 28, 2017 at 2:36 Rayce Rossum asked Feb 28, 2017 at 2:02 Rayce RossumRayce Rossum 411 silver badge3 bronze badges 2
  • Could you solve it? I have the same problem – Marian Klühspies Commented Mar 28, 2017 at 14:01
  • I have the same problem, plus it for anyone can help ^-^ – phan ngoc Commented Apr 3, 2017 at 1:29
Add a ment  | 

3 Answers 3

Reset to default 4

Just Install or run this mand and good to go:

npm install ws bufferutil utf-8-validate

I got this error in a NextJS app (13.0.1) using socket.io.

I solved installing webpack-node-externals:

npm install webpack-node-externals --save-dev

And then adding to next.config.js:

const nodeExternals = require('webpack-node-externals');

module.exports = withBundleAnalyzer({
    webpack(config) {
        config.externals = [nodeExternals()];    
        return config;
    },
    ...
});

It may not solve the OP case specifically, but may be useful for anyone having this issue with NextJS.

For those not using NextJS, adding the code below to webpack.config.js should also work:

const nodeExternals = require('webpack-node-externals');
...
module.exports = {
    ...
    target: 'node', // in order to ignore built-in modules like path, fs, etc.
    externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
    ...
};

UPDATE: upgrade ws v2.x can fix this!

change Receiver.js in wsmodule like this:

var isValidUTF8 = require('./Validation')
...
if (!isValidUTF8(messageBuffer)) {
  ...
}

you can do this just make it work, but it's not a good solution for this, it seems like that there is a wrong export of Validation module, you may send a PR to ws to fix this.

本文标签: javascriptNodejs and Socketio UTF8 Validation TypeError coming from wsStack Overflow