Cannot install module via HTTP Admin API

Hi all,

I'm trying to install a custom module via the HTTP Admin API but with no success as I keep getting:

{
  "code": "MODULE_NOT_FOUND",
  "message": "Cannot find module '[ABSOLUTE PATH PATH TO MY MODULE DIR]'"
}

On node-red logs shows:

[0] 14 Jan 20:27:49 - [info] Installing module: [ABSOLUTE PATH PATH TO MY MODULE DIR], version: latest
[0] 14 Jan 20:27:49 - [debug] npm.cmd install --no-audit --no-update-notifier --save --save-prefix="~" --production [ABSOLUTE PATH PATH TO MY MODULE DIR]
[0] 14 Jan 20:27:51 - [debug] [out] + teste@0.0.1
[0] 14 Jan 20:27:51 - [debug] [out] updated 1 package in 0.12s
[0] 14 Jan 20:27:51 - [debug] rc=0
[0] 14 Jan 20:27:51 - [info] Installed module: [ABSOLUTE PATH PATH TO MY MODULE DIR]

I'm executing:

POST http://{{host}}/red/nodes
content-type: application/json
Accept: application/json
{
    "module":"[ABSOLUTE PATH PATH TO MY MODULE DIR]"
}

If I run the npm install [ABSOLUTE PATH PATH TO MY MODULE DIR] it works.

Any thoughts?
Thanks

Are you using windows? The fact it says npm.cmd makes me thing you are.

Can you share the actual path you are using? I wonder if there's a windows path separator issue here where we are failing to detect the path properly.

The log output says it has installed the module. Can you have a look in .node-red/node_modules to see if the module has been installed?

Hi Nick, thanks for the quick reply.

Yes I'm running on Windows. I'm also running node-red in "embedded mode".

The HTTP request is:

POST http://{{host}}/red/nodes
content-type: application/json
Accept: application/json
{
    "module":"C:\\@Work\\00_projects\\pxp\\src\\temp\\.gen\\teste"
}

node-red logs:

[0] 15 Jan 08:34:08 - [info] Installing module: C:\@Work\00_projects\pxp\src\temp\.gen\teste, version: latest[0] 15 Jan 08:34:08 - [debug] npm.cmd install --no-audit --no-update-notifier --save --save-prefix="~" --production C:\@Work\00_projects\pxp\src\temp\.gen\teste
[0] 15 Jan 08:34:10 - [debug] [out] + teste@0.0.1
[0] 15 Jan 08:34:10 - [debug] [out] added 2 packages from 2 contributors in 0.09s
[0] 15 Jan 08:34:10 - [debug] rc=0
[0] 15 Jan 08:34:10 - [info] Installed module: C:\@Work\00_projects\pxp\src\temp\.gen\teste

And the .node-red/node_modules:
Code_ErKN43Z7EJ

Thanks for the help.

Hi @knolleary,

any thoughts on this?

Thanks.

Hi @brunoshine

I haven't been able to reproduce locally, but I suspect it may be an issue with our path detection on Windows.

I haven't had a chance to dust off my Windows VM to test that theory.

Please can you raise an issue so we don't forget about it.

Nick

Hi @knolleary,

i've tried on a Mac and got the same error:

POST http://{{host}}/red/nodes
content-type: application/json
Accept: application/json

{
    "module":"/Users/bfigueir/@work/00_projects/pxp/src/temp/.gen/teste"
}
23 Jan 00:37:41 - [info] Installed module: teste
[0] 23 Jan 00:38:57 - [info] Installing module: teste, version: latest
[0] 23 Jan 00:38:57 - [trace] npm["install","--no-audit","--no-update-notifier","--save","--save-prefix=\"~\"","--production","/Users/bfigueir/@work/00_projects/pxp/src/temp/.gen/teste"]
[0] 23 Jan 00:38:57 - [debug] npm install --no-audit --no-update-notifier --save --save-prefix="~" --production /Users/bfigueir/@work/00_projects/pxp/src/temp/.gen/teste
[0] 23 Jan 00:38:57 - [debug] [out] + teste@1.0.0
[0] 23 Jan 00:38:57 - [debug] [out] updated 1 package in 0.107s
[0] 23 Jan 00:38:58 - [debug] rc=0
[0] 23 Jan 00:38:58 - [info] Installed module: teste
HTTP/1.1 400 Bad Request
X-Powered-By: Express
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Content-Length: 66
ETag: W/"42-pdDQMPIpR0JgSB/UW4tjdbiDs18"
Date: Thu, 23 Jan 2020 00:38:58 GMT
Connection: close

{
  "code": "MODULE_NOT_FOUND",
  "message": "Cannot find module 'teste'"
}

on that folder i've got a package.json file:


{
    "name": "teste",
    "version": "1.0.0",
    "description": "",
    "node-red":{
        "nodes":{
        "teste":"teste.js"
        }
    }
}

Thanks!

Hi @brunoshine

I still can't reproduce this.

What versions of npm and node.js are you using?

After the install, what does its entry in the dependencies section of ~/.node-red/package.json look like?

Hi @knolleary

npm: 6.9.0
node: v10.16.0

{
    "name": "node-red-project",
    "description": "A Node-RED Project",
    "version": "0.0.1",
    "private": true,
    "dependencies": {
        "teste": "file:../../temp/.gen/teste"
    }
}

The ~/.node-red/node_modules contains the teste package and its files:
image

If I restart the app, the module isn't loaded and does not show on the palette.

Thanks.

If I copy the teste folder to the ~/.nodered/nodes folder, and restart the app, the node gets loaded and starts showing on the palette.

Is there any way to tell node-red to reload the nodes palette without the need to restart the app?

thanks.

@brunoshine if a module is installed in ~/.node-red/node_modules then Node-RED should be loading it on startup. The fact it isn't is strange and also explains why you get the error - it installs the module then fails to find where it has been installed. There must be something else about your setup to explain this.

How are you running Node-RED? Is this a 'normal' install or are you doing something non-default with the configuration?

Hi @knolleary,

so I managed it to start working. I'm running node-red in a embeded mode and made some configurations changes, one being the userDir setting where I was pointing to a relative path ./src/node-red/.nodered/ loaded from environment variable. After some digging around the node-red code (debugging) I saw that on the filesystem.js node-red was trying to require the package it was not founding it. I then changed the userDir to a absolutePath and now its working.

Thanks for the guidance and all the help. I'll try to dig up a bit more on why the relative path is not working.

Once again thanks :slight_smile:

I am getting the same response in Windows only, I also the installed node is being added as dependency in node_red_config/package.json and the symlink is been created in node_red_config/node_modules. The node is only available in HTTP GET /nodes after I have restarted the server. Is there any workaround to this issue?
Version
node -> v10.16.0
npm -> 6.9.0
node-red -> 0.20.8

To avoid splitting the discussion, I've replied to your Stack Overflow question - https://stackoverflow.com/questions/63905066/code-module-not-found-was-returned-when-a-node-red-node-is-installed-using-the-h

1 Like