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

WebRTC replication plugin throw error in vite env #5841

Closed
croatialu opened this issue Apr 2, 2024 · 6 comments
Closed

WebRTC replication plugin throw error in vite env #5841

croatialu opened this issue Apr 2, 2024 · 6 comments

Comments

@croatialu
Copy link
Contributor

code:

  replicateWebRTC(
    {
      collection: database.users,
      topic: 'my-users-pool',
      connectionHandlerCreator: getConnectionHandlerSimplePeer({}),
      pull: {},
      push: {
      }
    }
  );

error:
image

@cleech
Copy link
Contributor

cleech commented Apr 2, 2024

I'm not trying to rule out an issue here, but as a data point I'm using the WebRTC replication with vite as a build tool without problems. Currently using rxdb 15.6.0 and vite 5.2.2

@pubkey
Copy link
Owner

pubkey commented Apr 2, 2024

Seems to come from RxDB and not from simple-peer. Can you enable source maps?

@croatialu
Copy link
Contributor Author

croatialu commented Apr 3, 2024

I'm not trying to rule out an issue here, but as a data point I'm using the WebRTC replication with vite as a build tool without problems. Currently using rxdb 15.6.0 and vite 5.2.2

https://stackblitz.com/edit/vitejs-rxdb-replication-webrtc?file=src%2Fdb%2Fplugins%2Freplication-webrtc%2Fconnection-handler-simple-peer.ts

I tried to reproduce this problem in a new project ("vite": "^5.2.6", "rxdb": "^15.16.0").

https://www.npmjs.com/package/readable-stream#usage-in-browsers
In the readable-stream introduction, "Polyfills are no longer required since version 4.2.0."

The version used in simple-peer is ^3.6.0 (https://github.com/feross/simple-peer/blob/f1a492d1999ce727fa87193ebdea20ac89c1fc6d/package.json#L20)

My thoughts: The problem may be caused by vite not configuring polyfill by default or using the wrong polyfill when building the simple-peer, and there is a problem when building (warning in the console). If we use simplepeer-min.js directly, which is a built product with polyfill inside, we don't have this problem.

On the whole,
Cause of the problem:
Some modules used in "simple-peer" lack corresponding polyfill or have problems with polyfill when vite is built. Causing vite to issue a warning.

Problem solution:

  1. The polyfill of the vite configuration module, such as readable-stream, etc. (What if I used a different build tool?)
  2. Directly use simplepeer-min.js with polyfill. (https://github.com/feross/simple-peer/blob/f1a492d1999ce727fa87193ebdea20ac89c1fc6d/package.json#L63)

@croatialu
Copy link
Contributor Author

croatialu commented Apr 3, 2024

Seems to come from RxDB and not from simple-peer. Can you enable source maps?

I think it's a matter of polyfill when building, you can try this: https://stackblitz.com/edit/vitejs-rxdb-replication-webrtc?file=src%2Fdb%2Fplugins%2Freplication-webrtc%2Fconnection-handler-simple-peer.ts

@pubkey
Copy link
Owner

pubkey commented Apr 8, 2024

I merged your PR, release will come in the next days.

pubkey added a commit that referenced this issue Apr 8, 2024
@pubkey
Copy link
Owner

pubkey commented Apr 17, 2024

Please reopen if still broken in the latest version.

@pubkey pubkey closed this as completed Apr 17, 2024
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

3 participants