peerjs icon indicating copy to clipboard operation
peerjs copied to clipboard

'parcelRequire is not defined' When used with snowpack.

Open davjhan opened this issue 4 years ago • 9 comments

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

davjhan avatar Nov 11 '20 05:11 davjhan

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>

arnu515 avatar Nov 27 '20 10:11 arnu515

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. :)

valdrox avatar Jun 15 '21 15:06 valdrox

Same error using Vitejs

Olyno avatar Jun 21 '21 00:06 Olyno

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

dp-IED avatar Jul 30 '21 19:07 dp-IED

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

arnu515 avatar Jul 31 '21 05:07 arnu515

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.

dp-IED avatar Jul 31 '21 05:07 dp-IED

@Olyno Did you find any solution?

major697 avatar Apr 07 '22 22:04 major697

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

Olyno avatar Apr 08 '22 11:04 Olyno

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.

chientrm avatar Apr 15 '22 23:04 chientrm

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

jonasgloning avatar Mar 08 '23 07:03 jonasgloning