如何使用PEERJS(导入和要求两者都失败)
我想在脚本中使用PEERJS(我在HTML文件中使用)。 当我尝试从“ PEERJS” 导入对等时,我会遇到一个错误,说“不能在模块外使用导入语句”。 当我尝试var peer = require(“ peerjs”)
时,我会遇到一个错误,只是说“未定义”。 有没有办法使用PEERJS?如果是,那是什么?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要在HTML文件中使用库,则需要将其文件包含在脚本标签中。
例如,在您的情况下,PEERJS文档指示添加此行:
然后您可以创建一个同行并连接。
在这里看看: peerjs
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:
and then you can create a peer and connect.
take a look here: PeerJS