node.js - Raspberry 和 nodered-nodejs-npm 语法错误

标签 node.js npm node-red

我正在尝试在 nodered 中为我的树莓派 pi3 安装传感器 Node 。该传感器为空气质量传感器SDS011,安装命令如下:

npm install node-red-contrib-sds011

好吧,我认为这是一些更新的问题,实际上是命令

node -v

给我“v4.4.5”作为答案。

问题是,当我尝试使用一些 npm 命令(如上面的传感器命令)时,我总是会收到此错误作为答案:

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3

此外,如果我尝试启动 node.red 控制台,则会出现类似的错误:

Starting as a systemd service.                                                                            
/usr/lib/node_modules/node-red/node_modules/fs-extra/lib/fs/index.js:93                                   
exports.write = function (fd, buffer, ...args) {                                                          
                                      ^^^                                                                 
SyntaxError: Unexpected token ...                                                                         
    at exports.runInThisContext (vm.js:53:16)                                                             
    at Module._compile (module.js:373:25)                                                                 
    at Object.Module._extensions..js (module.js:416:10)                                                   
    at Module.load (module.js:343:32)                                                                     
    at Function.Module._load (module.js:300:12)                                                           
    at Module.require (module.js:353:17)                                                                  
    at require (internal/module.js:12:17)                                                                 
    at Object.<anonymous> (/usr/lib/node_modules/node-red/node_modules/fs-extra/                          lib/index.js:6:3)                                                                                         
    at Module._compile (module.js:409:26)                                                                 
    at Object.Module._extensions..js (module.js:416:10)                                                   
nodered.service: Main process exited, code=exited, status=1/FAILURE                                       
nodered.service: Failed with result 'exit-code'.                                                          
nodered.service: Service RestartSec=100ms expired, scheduling restart.                                    
nodered.service: Scheduled restart job, restart counter is at 1.                                          
Stopped Node-RED graphical event wiring tool.                                                             
Started Node-RED graphical event wiring tool.                                                             
/usr/lib/node_modules/node-red/node_modules/fs-extra/lib/fs/index.js:93                                   
exports.write = function (fd, buffer, ...args) {                                                          
                                      ^^^                                                                 
SyntaxError: Unexpected token ...                                                                         
    at exports.runInThisContext (vm.js:53:16)                                                             
    at Module._compile (module.js:373:25)                                                                 
    at Object.Module._extensions..js (module.js:416:10)                                                   
    at Module.load (module.js:343:32)                                                                     
    at Function.Module._load (module.js:300:12)                                                           
    at Module.require (module.js:353:17)                                                                  
    at require (internal/module.js:12:17)                                                                 
    at Object.<anonymous> (/usr/lib/node_modules/node-red/node_modules/fs-extra/                          lib/index.js:6:3)                                                                                         
    at Module._compile (module.js:409:26)                                                                 
    at Object.Module._extensions..js (module.js:416:10)                                                   
nodered.service: Main process exited, code=exited, status=1/FAILURE                                       
nodered.service: Failed with result 'exit-code'.                                                          
nodered.service: Service RestartSec=100ms expired, scheduling restart.                                    
nodered.service: Scheduled restart job, restart counter is at 2.                                          
Stopped Node-RED graphical event wiring tool.                                                             
Started Node-RED graphical event wiring tool.                                                             
/usr/lib/node_modules/node-red/node_modules/fs-extra/lib/fs/index.js:93                                   
exports.write = function (fd, buffer, ...args) {                                                          
                                      ^^^                                                                 
SyntaxError: Unexpected token ...                                                                         
    at exports.runInThisContext (vm.js:53:16)                                                             
    at Module._compile (module.js:373:25)                                                                 
    at Object.Module._extensions..js (module.js:416:10)                                                   
    at Module.load (module.js:343:32)                                                                     
    at Function.Module._load (module.js:300:12)                                                           
    at Module.require (module.js:353:17)                                                                  
    at require (internal/module.js:12:17)                                                                 
    at Object.<anonymous> (/usr/lib/node_modules/node-red/node_modules/fs-extra/                          lib/index.js:6:3)                                                                                         
    at Module._compile (module.js:409:26)                                                                 
    at Object.Module._extensions..js (module.js:416:10)                                                   
nodered.service: Main process exited, code=exited, status=1/FAILURE                                       
nodered.service: Failed with result 'exit-code'.                                                          
nodered.service: Service RestartSec=100ms expired, scheduling restart.                                    
nodered.service: Scheduled restart job, restart counter is at 3.                                          
Stopped Node-RED graphical event wiring tool.                                                             
Started Node-RED graphical event wiring tool.                                                             
/usr/lib/node_modules/node-red/node_modules/fs-extra/lib/fs/index.js:93                                   
exports.write = function (fd, buffer, ...args) {                                                          
                                      ^^^                                                                 
SyntaxError: Unexpected token ...                                                                         
    at exports.runInThisContext (vm.js:53:16)                                                             
    at Module._compile (module.js:373:25)                                                                 
    at Object.Module._extensions..js (module.js:416:10)                                                   
    at Module.load (module.js:343:32)                                                                     
    at Function.Module._load (module.js:300:12)                                                           
    at Module.require (module.js:353:17)                                                                  
    at require (internal/module.js:12:17)                                                                 
    at Object.<anonymous> (/usr/lib/node_modules/node-red/node_modules/fs-extra/                          lib/index.js:6:3)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Failed with result 'exit-code'.
nodered.service: Service RestartSec=100ms expired, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 4.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
/usr/lib/node_modules/node-red/node_modules/fs-extra/lib/fs/index.js:93
exports.write = function (fd, buffer, ...args) {
                                      ^^^
SyntaxError: Unexpected token ...
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/lib/node_modules/node-red/node_modules/fs-extra/lib/index.js:6:3)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Failed with result 'exit-code'.
nodered.service: Service RestartSec=100ms expired, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 5.
Stopped Node-RED graphical event wiring tool.
nodered.service: Start request repeated too quickly.
nodered.service: Failed with result 'exit-code'.
Failed to start Node-RED graphical event wiring tool.

一些建议?

非常感谢。

最佳答案

NodeJS v4.4.5 非常旧,完全不再支持(已于 2018 年 4 月停产)。

Node-RED 目前至少需要 NodeJS 版本 8.x ( https://nodered.org/docs/faq/node-versions )

您需要升级您的系统,我建议您使用 here 链接到的脚本因为它将升级到最新的 NodeJS 和 Node-RED。

关于node.js - Raspberry 和 nodered-nodejs-npm 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60132012/

相关文章:

node.js - ionic 构建在运行或部署到应用程序时不反射(reflect)更改

javascript - 如何在 Node Red 中同时运行多个查询?

node.js - 使用 node-red GPIO 或 i2c 通过 i2c 发送 ascii 字符串命令

JavaScript promise : a problem with setTimeout inside a promise race

node.js - 创建要在 bash 中使用的 Node Js 命令行缓冲区

node.js - 从 WAF 迁移到 GYP - 包括库在内的问题

javascript - 安装和使用特定 npm 包时遇到问题。我究竟做错了什么?

node.js - Bower 不复制项目文件夹中的文件

javascript - 使用 NodeJS 查找图像中是否存在 Logo

node.js - 如何编写在 sense HAT 模拟器上点亮 LED 的函数