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

Cannot read property 'call' of undefined #823

Open
m00nwtchr opened this issue Jun 14, 2021 · 11 comments
Open

Cannot read property 'call' of undefined #823

m00nwtchr opened this issue Jun 14, 2021 · 11 comments

Comments

@m00nwtchr
Copy link

m00nwtchr commented Jun 14, 2021

I get this error when using the lib in the browser:

Uncaught (in promise) TypeError: Cannot read property 'call' of undefined
    at new hd (vendor.57ab6ea3.js:19)
    at new vh (vendor.57ab6ea3.js:22)
    at index.c008e8f0.js:1
hd @ vendor.57ab6ea3.js:19
vh @ vendor.57ab6ea3.js:22
(anonymous) @ index.c008e8f0.js:1
Promise.then (async)
sendMic @ index.c008e8f0.js:1
wt @ vendor.57ab6ea3.js:1
Et @ vendor.57ab6ea3.js:1
n @ vendor.57ab6ea3.js:1

the stack trace is obfuscated but the line it points to seems to be in the readable-stream module. (i think its this one? https://github.com/nodejs/readable-stream/blob/master/lib/_stream_duplex.js#L60)
Code:

            navigator.mediaDevices.getUserMedia({
                audio: true,
                video: false
            }).then((stream) => {
                createPeer(this.socket as Socket);

                peer.addStream(stream);
            });
        }
function createPeer(socket: Socket) {
    if (!peer) {
        peer = new Peer({
            initiator: true
        });

        socket.on('peer-signal', (data) => {
                peer.signal(data);
        });

        peer.on('signal', data => {
            socket.emit('peer-signal', data)
        });
    }
    return peer;
}
@m00nwtchr m00nwtchr changed the title Cannot read property 'call' of undefine Cannot read property 'call' of undefined Jun 15, 2021
@m00nwtchr
Copy link
Author

Not sure if that's relevant but i'm using ViteJS (https://vitejs.dev) to build the app

@sy1vain
Copy link

sy1vain commented Jun 24, 2021

Not sure if that's relevant but i'm using ViteJS (https://vitejs.dev) to build the app

That is absolutely relevant. This is an issue with circular dependencies, see nodejs/readable-stream#348 That should be resolved in future updates, but for now a work around is needed.

Following that thread and some forks I currently use patch-package to apply some patches.

@m00nwtchr
Copy link
Author

Ok, thanks

@m00nwtchr
Copy link
Author

Can you share the patch that you apply to (presumably) the readable-stream package? @sy1vain
I tried this (https://gist.github.com/lmarianski/84a1233ddc9ee098ba443359a7e0f8ce), based on the fork mentioned at the end of that thread but now i'm getting this: (this time i enabled sourcemaps)

_stream_readable.js:180 Uncaught (in promise) TypeError: Cannot read property 'call' of undefined
    at jg.rp (_stream_readable.js:180)
    at new eg (_stream_duplex.js:57)
    at new jg (index.js:29)
    at webrtc.ts:9

@m00nwtchr
Copy link
Author

m00nwtchr commented Jul 5, 2021

Nvm, looks like i just had to install the events package

@sy1vain
Copy link

sy1vain commented Jul 5, 2021

For future reference I am using the attached file. Rename to .patch instead of .txt and place it in your patches folder.

This should only be a temporary workaround until the readable-stream packages is fixed and updated here.

simple-peer++readable-stream+3.6.0.txt

@halower
Copy link

halower commented Apr 26, 2022

@m00nwtchr I also encountered it, and I also used vite. Do you have a solution

@nosovk
Copy link

nosovk commented Aug 29, 2022

it seems that original problem nodejs/readable-stream#348 has fixed, it should be gone for now. But it's not :)

@remaininlight
Copy link

Working for me now using:

npm install -D vite-compatible-readable-stream

Thanks @m00nwtchr for:
npm install -D events

Fake process for the browser:
npm install -D process global
Then add this before you use SimplePeer:

import global from 'global'
import * as process from "process";
global.process = process;

Add this to your vite.config.ts:

  resolve: {
    alias: {
      "readable-stream": "vite-compatible-readable-stream"
    },
  },

Think that's most of what I did, good luck!

paul-thebaud added a commit to casperholders/casperholdersfront that referenced this issue Sep 26, 2022
See nodejs/readable-stream#348 and feross/simple-peer#823
This commit will probably be reverted in near future when nodejs readable stream will be compatible with vite
@iburakov
Copy link

Throwing in a piece of info that wasn't obvious to me, since it might save a bit of someone's time:

If in your vite.config you've set up something like this during development

  optimizeDeps: {
    esbuildOptions: {
      plugins: [
        NodeModulesPolyfills(),
        GlobalsPolyfills({
          process: true,
          buffer: true,
        }),
      ],
      define: {
        global: "globalThis",
      },
    },
  },

then it will work during development, but will break in production build, since Vite uses separate build pipelines for development (esbuild) and production (Rollup).

@remaininlight's workaround worked perfectly for production and didn't break development server (thanks!)

Upstream issue was closed as completed indeed, but it isn't immediately clear if the issue was really fixed in the readable-stream codebase itself, couldn't find any references of it in the changelog. Maybe the 4.x release? Currently simple-peer uses 3.x.

@kikichen77
Copy link

Hi! can you tell me do you solve this problem at last?
_stream_readable.js:180 Uncaught (in promise) TypeError: Cannot read property 'call' of undefined
at jg.rp (_stream_readable.js:180)
at new eg (_stream_duplex.js:57)
at new jg (index.js:29)
at webrtc.ts:9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants