首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用NPM模块“file- starting”启动Node-RED时出现意外令牌错误

使用NPM模块“file- starting”启动Node-RED时出现意外令牌错误
EN

Stack Overflow用户
提问于 2017-09-13 14:16:57
回答 1查看 4K关注 0票数 0

我目前正在用Node-RED开发一个应用程序,我想使用NPM的一些模块。有一个来自James的模块,它自动化了我可以使用的NPM模块(节点-红色-控制-npm)的实现。

不过,我希望首先对node.js进行更全面的手动实现,并更好地理解它的工作原理(我对node.js还不熟悉)。所以,我没有使用这个模块,而是作为官方的节点-红色指南,这里说。

  1. 相应地在functionGlobalContext文件中编辑settings.js属性,例如使用ccount NPM包:

代码语言:javascript
复制
functionGlobalContext: {
    // os:require('os'),
    // octalbonescript:require('octalbonescript'),
    // jfive:require("johnny-five"),
    // j5board:require("johnny-five").Board({repl:false})
// fileExists:require("file-exists") //DOESN'T WORK!!
ccount:require('ccount') //WORKS FINE!!
},

  1. 在节点红色函数节点中,我将:

代码语言:javascript
复制
var ccount = context.global.get('ccount');

msg.a = ccount('((())))))', '(') //=> 2
msg.b = ccount('pepe', ')') //=> 1

return msg;

  1. 伯爵工作得很好。现在,我对文件进行了同样的操作,如其README.md文件中的示例代码所示:

代码语言:javascript
复制
    functionGlobalContext: {
        // os:require('os'),
        // octalbonescript:require('octalbonescript'),
        // jfive:require("johnny-five"),
        // j5board:require("johnny-five").Board({repl:false})
	fileExists:require("file-exists") //DOESN'T WORK!!
	// ccount:require('ccount') //WORKS FINE!!
    },

  1. 在Node-RED中,我在一个函数块中添加了:

代码语言:javascript
复制
fileExists('/media/pi/SMOOTHIE/firmware.cur', (err, exists) => console.log(exists)) // OUTPUTS: true or false

console.log(fileExists.sync('/media/pi/SMOOTHIE/firmware.cur')) // OUTPUTS: true or false

return msg;

当我执行节点红色启动时,控制台的输出是:

代码语言:javascript
复制
pi@raspberrypi:~ $ node-red-start

Start Node-RED

Once Node-RED has started, point a browser at http://192.168.1.104:1880
On Pi Node-RED works better with the Firefox or Chrome browser

Use   node-red-stop                          to stop Node-RED
Use   node-red-start                         to start Node-RED again
Use   node-red-log                           to view the recent log output
Use   sudo systemctl enable nodered.service  to autostart Node-RED at every boot
Use   sudo systemctl disable nodered.service to disable autostart on boot

Starting as a systemd service.
Started Node-RED graphical event wiring tool..
Error loading settings file: /home/pi/.node-red/settings.js
[SyntaxError: Unexpected token =]

节点-红色日志输出如下:

代码语言:javascript
复制
13 Sep 19:29:20 - [info] Starting flows
13 Sep 19:29:20 - [info] Started flows
13 Sep 19:29:20 - [info] serial port /dev/ttyACM0 opened at 57600 baud 8N1
13 Sep 19:30:25 - [info] Stopping flows
13 Sep 19:30:25 - [info] serial port /dev/ttyACM0 closed
13 Sep 19:30:25 - [info] Stopped flows
13 Sep 19:30:25 - [info] Starting flows
13 Sep 19:30:25 - [info] Started flows
13 Sep 19:30:25 - [info] serial port /dev/ttyACM0 opened at 57600 baud 8N1
Stopping Node-RED graphical event wiring tool....
13 Sep 19:31:54 - [info] Stopping flows
Stopped Node-RED graphical event wiring tool..
Started Node-RED graphical event wiring tool..
Error loading settings file: /home/pi/.node-red/settings.js
[SyntaxError: Unexpected token =]
Started Node-RED graphical event wiring tool..
Started Node-RED graphical event wiring tool..
Error loading settings file: /home/pi/.node-red/settings.js
[SyntaxError: Unexpected token =]
Started Node-RED graphical event wiring tool..
Error loading settings file: /home/pi/.node-red/settings.js
[SyntaxError: Unexpected token =]
Started Node-RED graphical event wiring tool..
Error loading settings file: /home/pi/.node-red/settings.js
[SyntaxError: Unexpected token =]

我没别的事要查了。这个过程很好,因为它适用于另一个npm节点。文件存在模块(https://www.npmjs.com/package/file-exists)是由麻省理工学院的一些人制作和维护的,每天下载大约80000次,所以我认为它应该能工作。在这个时候,GitHub回购没有提到任何其他问题。我做错什么了?

谢谢。

编辑:节点-e的输出“要求”(‘./EDIT ings.js’);

代码语言:javascript
复制
pi@raspberrypi:~/.node-red $ node -e "require('./settings.js');"
/home/pi/.node-red/node_modules/file-exists/index.js:4
function fileExists (filepath, options, done = function () {}) {
                                         ^

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> (/home/pi/.node-red/settings.js:179:13)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
pi@raspberrypi:~/.node-red $ 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-13 21:13:52

文件存在节点所需的Nodev6.x或更高版本,错误是因为它使用的是节点v4.8.x不理解的新语法。

您可以使用这里中的Node-RED升级脚本,这将将Node-RED升级到最新版本,并将NodeJS升级到最新的v6构建。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46199939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档