Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error init 'socket.io' for node #3682

Closed
nono002 opened this issue Nov 8, 2020 · 6 comments
Closed

error init 'socket.io' for node #3682

nono002 opened this issue Nov 8, 2020 · 6 comments
Labels
unable to reproduce We were unable to reproduce the issue

Comments

@nono002
Copy link

nono002 commented Nov 8, 2020

  1. server.js
const content = require('fs').readFileSync(__dirname + '/index.html', 'utf8');

const httpServer = require('http').createServer((req, res) => {
  // serve the index.html file
  res.setHeader('Content-Type', 'text/html');
  res.setHeader('Content-Length', Buffer.byteLength(content));
  res.end(content);
});

const io = require('socket.io')(httpServer);

io.on('connect', socket => {
  console.log('connect');
});

httpServer.listen(3000, () => {
  console.log('go to http://localhost:3000');
});

==============================
2) index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Minimal working example</title>
</head>
<body>
    <ul id="events"></ul>

    <script src="/socket.io/socket.io.js"></script>
    <script>
        const $events = document.getElementById('events');

        const newItem = (content) => {
          const item = document.createElement('li');
          item.innerText = content;
          return item;
        };

        const socket = io();

        socket.on('connect', () => {
          $events.appendChild(newItem('connect'));
        });
    </script>
</body>
</html>

===========================
error:

c:\111\node_modules\socket.io\dist\index.js:248
stream_1.pipeline(readStream, zlib_1.createGzip(), res, onError)
;
^

TypeError: stream_1.pipeline is not a function
at Function.sendFile (c:\111\node_modules\socket.io\dist\index.js:248:26)
at Server.serve (c:\111\node_modules\socket.io\dist\index.js:224:16)
at Server.srv.on (c:\111\node_modules\socket.io\dist\index.js:185:22)
at emitTwo (events.js:126:13)
at Server.emit (events.js:214:7)
at parserOnIncoming (_http_server.js:602:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:116:23)

(win7 x64)

@nono002
Copy link
Author

nono002 commented Nov 8, 2020

error only for 3.0 release.
2.3.0 is Ok

@darrachequesne
Copy link
Member

@nono002 hi! which version of Node.js are you using? According to the documentation here, stream.pipeline() was added in v10.0.0. Are you using a previous version of Node.js?

@darrachequesne darrachequesne added the unable to reproduce We were unable to reproduce the issue label Nov 9, 2020
@cellcrowd
Copy link

I was getting this very same error using Node.js v8. The version mentioned in the docs should be bumped: https://socket.io/docs/server-installation/

@nono002
Copy link
Author

nono002 commented Nov 9, 2020

@nono002 hi! which version of Node.js are you using? According to the documentation here, stream.pipeline() was added in v10.0.0. Are you using a previous version of Node.js?

v8.9.4

@nono002
Copy link
Author

nono002 commented Nov 9, 2020

upgarde node to v12.19.0
OK

@darrachequesne
Copy link
Member

@cellcrowd good catch, thanks! the version was updated: https://socket.io/docs/v3/server-installation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unable to reproduce We were unable to reproduce the issue
Projects
None yet
Development

No branches or pull requests

3 participants