如何使用PEERJS(导入和要求两者都失败)

发布于 2025-01-28 00:56:02 字数 174 浏览 4 评论 0原文

我想在脚本中使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

π浅易 2025-02-04 00:56:02

如果要在HTML文件中使用库,则需要将其文件包含在脚本标签中。
例如,在您的情况下,PEERJS文档指示添加此行:

<script src="https://unpkg.com/[email protected]/dist/peerjs.min.js"></script>

然后您可以创建一个同行并连接。

在这里看看: 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:

<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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文