javascript - Node.js 未处理的PromiseRejectionWarning

标签 javascript node.js arduino

我一直在尝试使用 Node.js 对这个机器人汽车进行编程以使其移动,但是在运行该程序后,它给了我这个错误。

您的环境已设置为使用 Node.js 8.9.4 (x64) 和 npm。

C:\Users\john>node 4wd.js
http://localhost:3030
(node:8660) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Error: Opening /dev/ttyUSB0: Unknown error code 3
(node:8660) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这是什么意思? 这是否意味着它有效?

最佳答案

这意味着您运行的 Promises 之一被拒绝 - 这意味着它没有解析值,而是因错误而拒绝。

更具体地说,我们可以看到问题出在Error: Error: Opening/dev/ttyUSB0: Unknown error code 3。我最好的猜测是您的程序无权进入该目录(USB),因此被拒绝并出现该错误。

为了防止拒绝,请在 .then 之后添加 catch 来处理错误。

了解有关 promise 的更多信息 here .

关于javascript - Node.js 未处理的PromiseRejectionWarning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48953750/

相关文章:

node.js - Mongoose - CastError : 'Cast to undefined failed for value "[object Object ]"at path "trainers"

angularjs - 环回中的动态 datasource.json

mysql - 我需要担心使用 sequelize 的 node.js 的 mysql 连接池吗?

javascript - AngularJS - 类型错误 : Cannot read property 'go' of undefined

javascript - 尝试读取 React js 中 API 返回的响应时出现未定义问题

javascript - 有没有办法将 json 对象转换为 json l 文件

c - 在 Arduino 上每 y 秒执行一次函数 x 秒

java - 将 delayMicroseconds 函数添加到标准 firmata 以运行带处理的 Arduino

c++ - 如何使用 gcc 内联汇编代码访问成员变量

javascript - jQuery 值属性选择器未返回正确数量的元素