我在node.js/ node -RED中开始了我的第一步,并且需要从一个节点组件执行http请求(GET、POST,使用和不使用xml有效负载),所以我认为xmlhttprequest是我的最佳选择。我已经安装了npm。实际上将其安装在~/.node-red/ node _modules和/usr/local/lib/node_modules中,但每次启动node-RED时,它都不会激活节点组件,并显示以下错误:
Welcome to Node-RED
===================
7 Aug 09:05:20 - [info] Node-RED version: v0.17.5
7 Aug 09:05:20 - [info] Node.js version: v6.11.2
7 Aug 09:05:20 - [info] Darwin 16.7.0 x64 LE
7 Aug 09:05:20 - [info] Loading palette nodes
7 Aug 09:05:21 - [warn] ------------------------------------------------------
7 Aug 09:05:21 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node
7 Aug 09:05:21 - [warn] [synaptiq-solar] Error: Cannot find module 'xmlhttprequest'
7 Aug 09:05:21 - [warn] ------------------------------------------------------
7 Aug 09:05:21 - [info] Settings file : /Users/rudi/.node-red/settings.js
7 Aug 09:05:21 - [info] User directory : /Users/rudi/.node-red
7 Aug 09:05:21 - [info] Flows file : /Users/rudi/.node-red/flows_Rudi.local.json
7 Aug 09:05:21 - [info] Server now running at http://127.0.0.1:1880/
7 Aug 09:05:21 - [info] Waiting for missing types to be registered:
7 Aug 09:05:21 - [info] - synaptiq-solar
我的组件的名称是synaptiq-solar,它的代码以如下所示的要求xmlhttprequest组件开始:
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
另外,我的package.json有一个引用xmlhttprequest的依赖项部分,如下所示:
{
"name": "synaptiq-solar",
"version": "0.0.1",
"description": "Just playing around, learning how to create a custom node",
"dependencies": {
"xmlhttprequest": "1.8.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"node-red": {
"nodes": {
"synaptiq-solar": "synaptiq-solar.js"
}
},
"author": "Smappee n.v.",
"license": "ISC"
}
那么我到底做错了什么呢?我应该在其他位置安装xmlhttprequest组件吗?node-RED正在寻找依赖组件的另一个lib目录吗?
发布于 2017-08-07 16:02:02
如果一个自定义节点有一个外部依赖项,它应该在它的package.json
文件中声明它,以便它们与您的自定义模块一起安装。
如果您已经将其创建为“本地”节点(在nodes
目录中只有一个.js
和.html
文件,没有package.json
),那么您应该将其创建为一个模块。
该文档包含有关正确打包节点的指南:https://nodered.org/docs/creating-nodes/packaging
https://stackoverflow.com/questions/45541388
复制相似问题