0

I tried to make a small app using peerjs but when I tried to import Peer from "peerjs", my code crash with:

Uncaught ReferenceError: assignment to undeclared variable parcelRequire

At http://localhost:8080/_snowpack/pkg/peerjs.js:20

I didn't find anything on internet. And I don't why snowpack is using parcel because I didn't install any plugin I tried to import Peerjs with Skypack but it's same. On the other hand, when I test to import another library, here I tested with canvas-confetti, it work. So I don't know why Snowpack doesn't like Peerjs

Andrew Stegmaier
  • 3,429
  • 2
  • 14
  • 26
LitleCodeur
  • 21
  • 1
  • 8
  • I find that's because PeerJS is using Parcel to bundle. The problem is that Parcel doesn't produce strict code but a module is always strict... so it can't be imported. But I don't know how to fix that without modify the peerjs file – LitleCodeur Mar 27 '21 at 15:02

4 Answers4

1

You can fix this by adding esModuleInterop: true and allowSyntheticDefaultImports: true to tsconfig.json

Rito
  • 11
  • 2
0

This is an issue with the peerJs library.

You can see the line of code that is causing this issue here You could perhaps mitigate it by setting window.parcelRequire before importing the peerJs library. Consider filing an issue to peerJs's github.

Charlie Bamford
  • 1,268
  • 5
  • 18
0

There is a similar error in parcel-bundler https://github.com/parcel-bundler/parcel/issues/1401 used by the status-widget developed by Atlassian https://bitbucket.org/atlassian/statuspage-status-widget/issues/3/uncaught-referenceerror-parcelrequire-is

julian-alarcon
  • 297
  • 3
  • 9
0

For Instance Fix

Add variable in node_modules/ peerjs/dist/peerjs.js

var parcelRequire

instead of

parcelRequire
Balaji
  • 9,657
  • 5
  • 47
  • 47