遇到问题 installing/using xmlhttprequest

Having trouble installing/using xmlhttprequest

我正在节点中迈出第一步。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 目录来查找依赖组件?

如果自定义节点有外部依赖项,它应该在其 package.json 文件中声明它,以便它们与您的自定义模块一起安装。

如果您将其创建为 "local" 节点(在 nodes 目录中只有 .js.html 文件,没有 package.json) ,您应该将其创建为模块。

文档包含正确打包节点的指南:https://nodered.org/docs/creating-nodes/packaging