peers / peerjs

Simple peer-to-peer with WebRTC.
https://peerjs.com
MIT License
12.29k stars 1.42k forks source link

'parcelRequire is not defined' When used with snowpack. #753

Closed davjhan closed 1 year ago

davjhan commented 3 years ago

Hello,

I am using this library with svelte and snowpack.

snowpack build runs fine but If i snowpack dev, the following line will throw an error:

import Peer from 'peerjs'
const peer = new Peer()

It throws the following error:

Uncaught ReferenceError: parcelRequire is not defined

Source:

http://localhost:8080/web_modules/peerjs.js [:4:889]
ReferenceError: parcelRequire is not defined
    at parcelRequire.EgBh (http://localhost:8080/web_modules/peerjs.js:4:889)
    at http://localhost:8080/web_modules/peerjs.js:4:911
    at createCommonjsModule (http://localhost:8080/web_modules/common/_commonjsHelpers-8a10f9bf.js:14:5)
    at http://localhost:8080/web_modules/peerjs.js:3:18

I am using v1.3.0

arnu515 commented 3 years ago

I found a fix: In your index.html, or the main html page (template.html sometimes), put this in the <head> tag:

<script>
    var parcelRequire;
</script>
valdrox commented 3 years ago

I got this error when using electron-builder in build mode and @arnu515 's fix solved it for me. Just adding this to help the next person keyword search this solution faster. :)

Olyno commented 3 years ago

Same error using Vitejs

ColleSerre commented 3 years ago

I swear this will sound like a joke but when I use @arnu515's answer I get prompted to print the web page.

arnu515 commented 3 years ago

Sometimes this happens when you do python and js together. You might have added a print instead of a console.log. The former statement prompts you to print the page. @ColleSerre

ColleSerre commented 3 years ago

Good call, that was it. I’ve been coding in Dart for the last 8 months so I guess my muscle memory just screwed me up.

Le 31 juil. 2021 à 07:03, arnu515 @.***> a écrit :

 Sometimes this happens when you do python and js together. You might have added a print instead of a console.log. The former statement prompts you to print the page.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

major697 commented 2 years ago

@Olyno Did you find any solution?

Olyno commented 2 years ago

Not at all, I just stopped use this project @major697

chientrm commented 2 years ago

I found a fix: In your index.html, or the main html page (template.html sometimes), put this in the <head> tag:

<script>
    var parcelRequire;
</script>

Confirm this solution works for Svelte and SvelteKit which use ViteJS.

jonasgloning commented 1 year ago

This has been solved in v1.4. Importing PeerJS should work with Snowpack, Vite, and Svelte.