【发布时间】:2019-01-03 15:46:48
【问题描述】:
我尝试使用来自 https://github.com/aholstenson/miio 的 miIO 库,但是当我尝试使用它时出现错误 ReferenceError: require is not defined
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
const mio = require('./lib');
mio.device({ address: '192.168.31.148' })
.then(device => console.log('Connected to', device))
.catch(err => handleErrorHere);
</script>
</body>
</html>
谁能帮我解释一下为什么这段代码出错了?
【问题讨论】:
-
是的,它是一个 NodeJS 模块,这意味着它在 Node(在服务器上)中运行,而不是在浏览器中。
miio is MIT-licensed and requires at least Node 6.6.0. -
@Deiv — Browserify 不会将大多数对 Node API 的依赖转变为在浏览器中工作的东西。
标签: javascript