peerjs
peerjs copied to clipboard
'parcelRequire is not defined' When used with snowpack.
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
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>
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. :)
Same error using Vitejs
I swear this will sound like a joke but when I use @arnu515's answer I get prompted to print the web page.
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
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.
@Olyno Did you find any solution?
Not at all, I just stopped use this project @major697
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.
This has been solved in v1.4
.
Importing PeerJS should work with Snowpack, Vite, and Svelte.