'How to use peerjs (import and require both fail)
I want to use peerjs in a script (that I use in a html file).
When I try import Peer from "peerjs"
, I get an error saying "Cannot use import statement outside a module".
When I try var Peer = require("peerjs")
, I get an error saying simply "require is not defined".
Is there a way to use peerjs ? If yes, what is it ?
Solution 1:[1]
if you want to use a library inside an HTML file you need to include its file in a script tag.
for example in your case, PeerJS documentation instructs to add this line:
<script src="https://unpkg.com/[email protected]/dist/peerjs.min.js"></script>
and then you can create a peer and connect.
take a look here: PeerJS
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | relbns |