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

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

Closed
davjhan opened this issue Nov 11, 2020 · 10 comments
Closed

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

davjhan opened this issue Nov 11, 2020 · 10 comments

Comments

@davjhan
Copy link

davjhan commented Nov 11, 2020

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
Copy link

arnu515 commented Nov 27, 2020

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
Copy link

valdrox commented Jun 15, 2021

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
Copy link

Olyno commented Jun 21, 2021

Same error using Vitejs

@dp-IED
Copy link

dp-IED commented Jul 30, 2021

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

@arnu515
Copy link

arnu515 commented Jul 31, 2021

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

@dp-IED
Copy link

dp-IED commented Jul 31, 2021 via email

valrus added a commit to valrus/collaborative-blackout-poetry that referenced this issue Feb 20, 2022
@major697
Copy link

major697 commented Apr 7, 2022

@Olyno Did you find any solution?

@Olyno
Copy link

Olyno commented Apr 8, 2022

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

@chientrm
Copy link

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
Copy link
Member

jonasgloning commented Mar 8, 2023

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

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

8 participants