-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Library fails with missing global declarations when run inside nodejs (ES6) #36
Comments
Hi @lukebayes , It would be possible to provide two different bundles in y-webrtc: one for the browser and one for node. These separate bundles could be exported using conditional imports like I'm doing in I can't import the main import from simple-peer, because it can only be bundled with browserify (and probably some esoteric webpack configuration). The y-webrtc node bundle should import the main import, the y-webrtc browser import should continue importing the pre-bundled version. I'm sorry, but this is not a high priority for me. I'll leave this ticket open and will accept a PR that implements what I described above. |
Hey @dmonad, Thanks for the response. I definitely understand how difficult it can be to get work like this into the top of a priority queue. No problem here. My main hope is to get a place online where anyone else bumping into these issues may find a workaround. I'd like to see if I can't get simple-peer to build more appropriately across their supported environments. I believe that would remove some (nearly all) of the work that showed up here. Thanks! |
I also ran into this issue while trying to set up this library in a next.js project. For anyone running into this issue, make sure your code containing the |
Hi, just a quick note that I ran into this while (loosely) following https://syncedstore.org/docs/svelte/ to setup y-webrtc in my svelte app with syncedstore. When I ll find some time, I'll try to dig a bit deeper, and post updated information if I find any. |
This works on my side:
|
I'm attempting to run a Webrtc client within browsers and nodejs.
The browser build seems to work well. The nodejs (ES6 modules) side is having some problems.
Here is some sample code that triggers the first error from nodejs (in a file named,
demo.js
).Running this with
node demo.js
fails with the following error:I was able to work around this issue by adding the following to the top of my application entry point (above any imports).
This allows the service to start, but whenever a connection is made from a separate browser client, the following error is thrown:
After digging a little bit, it looks like
y-webrtc
is loading a pre-minified build ofsimple-peer
that may have been built for the browser and not nodejs.I was unable to get a similar global hack working for this issue, and instead forked the y-webrtc repo into a vendor folder, loaded as a git submodule and referred to that version from my node application and the npm published version from my browser client code.
I also had to add the following to my imports and update the
peerOpts
object:Unfortunately,
wrtc
requiresnode-pre-gyp
andnode-gyp
, which seem to be in a weird state at the moment, so I had to install those both globally, delete mynode_modules
folder and reinstall local modules in order to get the thing to work.Expected behavior
The library should work for either node or browser clients
Environment Information
v16.14.2
Linux beefcake 5.13.0-39-generic #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Additional context
FWIW, here's the commit that worked around the issue.
FWIW 2, I also tried pointing into the unminified build of simple-peer, but that did not want to build successfully for the browser (under esbuild with es6 modules) as there were nodejs modules being required in that dependency.
I understand that these issues probably aren't going to be trivial to solve from
y-webrtc
, so thought I'd post here in case others have the same problems, at least we can discuss workarounds.The text was updated successfully, but these errors were encountered: