我有一些代码在我的日常计算机上完美运行,但在尝试从树莓派(3 型号 B)启动时出现错误。错误如下:
> setInterval(async function () {
> ^^^^^
>
> SyntaxError: missing ) after argument list
> at exports.runInThisContext (vm.js:53:16)
> at Module._compile (module.js:414:25)
> at Object.Module._extensions..js (module.js:442:10)
> at Module.load (module.js:356:32)
> at Function.Module._load (module.js:311:12)
> at Function.Module.runMain (module.js:467:10)
> at startup (node.js:134:18)
> at node.js:961:3
我的代码是一个“简单”的 setInterval (1500 毫秒),其中包含 async/await:
setInterval(async function () {
var data = await foo();
var obj = new mongooseModel({
mk: data.mk,
name: data.name,
a: data.a,
b: data.b,
c: data.c,
v: data.v,
p: data.p,
l: data.l,
h: data.h,
o: data.o,
sn: data.sn,
n: data.n,
});
obj.save(function(err, tick) {
if (err) return console.log(err);
});
});
}, 1500);
还有人遇到过这个问题吗? 提前致谢!!
最佳答案
async/await
从 v7.6 开始受 Node.js 支持。您需要升级已安装的node.js版本或使用Promises。
关于node.js - NodeJS : Async/Await Raspberry Pi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46004077/