覆盆子和 nodered-nodejs-npm SyntaxError

Raspberry and nodered-nodejs-npm SyntaxError

我正尝试在 nodered 中为我的树莓派 pi3 安装一个传感器节点。传感器为空气质量传感器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。