Library and node in one package

Sorry Nick but the shared code shows that isn't what is being done. It has all the code in a single .js file which is what I'm saying shouldn't be done.

I have placed the code for the node and the code for the library separately.

  • Library: TestLib.js
  • Node: TestNode.js + TestNode.html

I've now found time over lunch to test this and I'm sad to say that it doesn't appear to be working:

0|Node-RED  | 21 Apr 13:54:50 - [error] [function:f8c2d9728fc3c9bd] Failed to load module : TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "..\..\..\..\data\node_modules\node-red-contrib-uibuilder" is not a valid package name imported from C:\src\nr\node_modules\@node-red\registry\lib\util.js
0|Node-RED  | 21 Apr 13:54:50 - [error] [function:f8c2d9728fc3c9bd] Function node failed to load external modules

I added a new module to a locally installed node package, changed the main entry and restarted node-red.

Need to have a look at the internal node-red code to see why it doesn't like the name.

What did you put in the setup tab of the Function node?

Are we looking at different code?

Has TestNode.js containing the node and TestLib.js containing the standalone module.

I have npm installed the example code from the repo linked above into ~/.node-red.

The node shows up in the palette as expected.

I add node-red-contrib-test-node to the setup tab of a Function node - and get the following error:

Failed to load module : Error [ERR_UNSUPPORTED_DIR_IMPORT]:  Directory import '/Users/nol/.node-red/node_modules/node-red-contrib-test-node' is not supported resolving ES modules imported from /Users/nol/code/node-red/node-red/packages/node_modules/@node-red/registry/lib/util.js

This is an issue with the mess that is esmodules.. not sure why it's being hit here as it should just work. Need to investigate properly

image

image

And the module is called index.js in the root folder:

'use strict'
module.exports = {
    fred: function fred() {
        console.log('hello')
    }
}

Here is the code in util.js that is having the issue:

function importModule(name) {
    var moduleInfo = require("./index").getModuleInfo(name);
    if (moduleInfo && moduleInfo.path) {
        var relPath = path.relative(__dirname, moduleInfo.path);
        return import(relPath);
    } else {
        // Require it here to avoid the circular dependency
        return require("./externalModules").import(name);
    }
}

I note that, for other modules that are being loaded for other function nodes (fs-extra, fast-glob, and googleapis), the else is being executed. However, for uibuilder, the if is being executed because require("./index").getModuleInfo(name) is returning something other than null which is returned for the others. I think that this might be because uibuilder's package.json has a type property:

  "main": "./index.js",
  "browser": "./front-end/uibuilderfe.min.js",
  "style": "./front-end/uib-styles.css",
  "types": "index.d.ts",
  "type": "commonjs",

I think that there needs to be an extra test because a type of "commonjs" should not be treated as an ECMA module. When the requireModule function attempts to use the dynamic import, it is not taking into account the main setting as far as I can tell, it is merely trying to import the folder name.

No.

OK, so not necessarily a problem with having everything in a single file - though I still think that is probably hard to manage in the future. You are getting the same issue as me.

So the problem is that the requireModule function needs a bit more encouragement to load the correct file when using a package that is both a node and a module.

Here is the log output where I tracked this down

0|Node-RED  | >>1>>  fs-extra
0|Node-RED  | >>2>>  fs-extra null
0|Node-RED  | >>5>>  fs-extra
0|Node-RED  | >>1>>  fast-glob
0|Node-RED  | >>2>>  fast-glob null
0|Node-RED  | >>5>>  fast-glob
0|Node-RED  | >>1>>  googleapis
0|Node-RED  | >>2>>  googleapis null
0|Node-RED  | >>5>>  googleapis
0|Node-RED  | >>1>>  googleapis
0|Node-RED  | >>2>>  googleapis null
0|Node-RED  | >>5>>  googleapis
0|Node-RED  | >>1>>  node-red-contrib-uibuilder
0|Node-RED  | >>2>>  node-red-contrib-uibuilder {
0|Node-RED  |   name: 'node-red-contrib-uibuilder',
0|Node-RED  |   version: '5.0.2',
0|Node-RED  |   local: true,
0|Node-RED  |   user: true,
0|Node-RED  |   path: 'C:\\src\\nr\\data\\node_modules\\node-red-contrib-uibuilder',
0|Node-RED  |   nodes: [
0|Node-RED  |     {
0|Node-RED  |       id: 'node-red-contrib-uibuilder/uibuilder',
0|Node-RED  |       name: 'uibuilder',
0|Node-RED  |       types: [Array],
0|Node-RED  |       enabled: true,
0|Node-RED  |       local: true,
0|Node-RED  |       user: false,
0|Node-RED  |       module: 'node-red-contrib-uibuilder',
0|Node-RED  |       version: '5.0.2'
0|Node-RED  |     },
0|Node-RED  |     {
0|Node-RED  |       id: 'node-red-contrib-uibuilder/uib-sender',
0|Node-RED  |       name: 'uib-sender',
0|Node-RED  |       types: [Array],
0|Node-RED  |       enabled: true,
0|Node-RED  |       local: true,
0|Node-RED  |       user: false,
0|Node-RED  |       module: 'node-red-contrib-uibuilder',
0|Node-RED  |       version: '5.0.2'
0|Node-RED  |     },
0|Node-RED  |     {
0|Node-RED  |       id: 'node-red-contrib-uibuilder/uib-cache',
0|Node-RED  |       name: 'uib-cache',
0|Node-RED  |       types: [Array],
0|Node-RED  |       enabled: true,
0|Node-RED  |       local: true,
0|Node-RED  |       user: false,
0|Node-RED  |       module: 'node-red-contrib-uibuilder',
0|Node-RED  |       version: '5.0.2'
0|Node-RED  |     }
0|Node-RED  |   ]
0|Node-RED  | }
0|Node-RED  | >>3>>  node-red-contrib-uibuilder
0|Node-RED  | >>4>>  node-red-contrib-uibuilder
0|Node-RED  | 21 Apr 14:23:57 - [info] Started flows
0|Node-RED  | 21 Apr 14:23:57 - [error] [function:f8c2d9728fc3c9bd] Failed to load module : TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "..\..\..\..\data\node_modules\node-red-contrib-uibuilder" is not a valid package name imported from C:\src\nr\node_modules\@node-red\registry\lib\util.js
0|Node-RED  | 21 Apr 14:23:57 - [error] [function:f8c2d9728fc3c9bd] Function node failed to load external modules

And the amended requireModule code that I used:

function importModule(name) {
    console.log('>>1>> ', name)
    var moduleInfo = require("./index").getModuleInfo(name);
    console.log('>>2>> ', name, moduleInfo)
    if (moduleInfo && moduleInfo.path) {
        console.log('>>3>> ', name)
        var relPath = path.relative(__dirname, moduleInfo.path);
        console.log('>>4>> ', name)
        return import(relPath);
    } else {
        console.log('>>5>> ', name)
        // Require it here to avoid the circular dependency
        return require("./externalModules").import(name);
    }
}

The screenshot you have shared show two different filenames... but lets move on.


It is the fact the module has already been recognised as a Node-RED module and had nodes loaded from it which is causing it to go down the path it is... and that path has never needed to handle this scenario.

Need to work through where this code path gets used and what side effects there are to any changes.

Sheesh! I need my eyes testing!

Ah, that makes more sense.


As a test, I took out the if statement and it all worked. Though I understand that is only because I happen to be only loading CommonJS modules.

1 Like

Fix pushed - will be in 3.0 - Fix importing external module from node-red module by knolleary · Pull Request #3541 · node-red/node-red · GitHub

2 Likes

I hope that I have understood it correctly. The pull request should solve the described problem?

I have applied the changes from the pull request to a new Node-RED installation (v. 2.2.2). The error message when loading the library via the function node is still displayed.

What error exactly are you getting?

Have you used npm to install the module in your .node-red directory?

I still get the same error message as described in the posts above.

I have not installed the package via npm. I just put the data into the nodesDir.

But I will try an installation.

Installing the package did not fix the error either.

This is the npm log generated by Node-RED when it tries to load the library.

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\nodejs\\nodejs\\node.exe',
1 verbose cli   'C:\\nodejs\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   '--production',
1 verbose cli   '--engine-strict',
1 verbose cli   'node-red-contrib-test-node'
1 verbose cli ]
2 info using npm@6.14.6
3 info using node@v14.6.0
4 verbose npm-session b2aea2bbf651c989
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 http fetch GET 404 https://registry.npmjs.org/node-red-contrib-test-node 1834ms
8 http fetch GET 404 https://registry.npmjs.org/node-red-contrib-test-node 259ms
9 silly fetchPackageMetaData error for node-red-contrib-test-node@latest 404 Not Found - GET https://registry.npmjs.org/node-red-contrib-test-node - Not found
10 timing stage:rollbackFailedOptional Completed in 1ms
11 timing stage:runTopLevelLifecycles Completed in 2195ms
12 verbose stack Error: 404 Not Found - GET https://registry.npmjs.org/node-red-contrib-test-node - Not found
12 verbose stack     at C:\nodejs\nodejs\node_modules\npm\node_modules\npm-registry-fetch\check-response.js:114:15
12 verbose stack     at processTicksAndRejections (internal/process/task_queues.js:93:5)
13 verbose statusCode 404
14 verbose pkgid node-red-contrib-test-node@latest
15 verbose cwd C:\nodejs\nodered222\user
16 verbose Windows_NT 10.0.19044
17 verbose argv "C:\\nodejs\\nodejs\\node.exe" "C:\\nodejs\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--production" "--engine-strict" "node-red-contrib-test-node"
18 verbose node v14.6.0
19 verbose npm  v6.14.6
20 error code E404
21 error 404 Not Found - GET https://registry.npmjs.org/node-red-contrib-test-node - Not found
22 error 404
23 error 404 'node-red-contrib-test-node@latest' is not in the npm registry.
24 error 404 You should bug the author to publish it (or use the name yourself!)
25 error 404 Note that you can also install from a
26 error 404 tarball, folder, http url, or git url.
27 verbose exit [ 1, true ]

Node-RED protocol:

22 Apr 10:07:33 - [info]

Welcome to Node-RED
===================

22 Apr 10:07:33 - [info] Node-RED version: v2.2.2
22 Apr 10:07:33 - [info] Node.js  version: v14.6.0
22 Apr 10:07:33 - [info] Windows_NT 10.0.19044 x64 LE
22 Apr 10:07:35 - [info] Loading palette nodes
22 Apr 10:07:36 - [debug] Module: node-red-contrib-test-node 0.0.1 C:\nodejs\nodered222\node_modules\node-red-contrib-test-node
22 Apr 10:07:37 - [info] Settings file  : C:\nodejs\nodered222\settings.js
22 Apr 10:07:37 - [info] Context store  : 'default' [module=memory]
22 Apr 10:07:37 - [info] User directory : C:/nodejs/nodered222/user
22 Apr 10:07:37 - [warn] Projects disabled : editorTheme.projects.enabled=false
22 Apr 10:07:37 - [info] Flows file     : C:\nodejs\nodered222\user\flows.json
22 Apr 10:07:39 - [info] Server now running at http://127.0.0.1:1880/
22 Apr 10:07:39 - [debug] loaded flow revision: 5de98fbfa87c90a857a65e1a892d49b3
22 Apr 10:07:39 - [debug] red/runtime/nodes/credentials.load : no user key present
22 Apr 10:07:39 - [debug] red/runtime/nodes/credentials.load : using default key
22 Apr 10:07:39 - [debug] red/runtime/nodes/credentials.load : keyType=system
22 Apr 10:07:39 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

22 Apr 10:07:39 - [trace] runtime event: {"id":"runtime-state","retain":true}
22 Apr 10:07:39 - [trace] runtime event: {"id":"runtime-deploy","payload":{"revision":"5de98fbfa87c90a857a65e1a892d49b3"},"retain":true}
22 Apr 10:07:39 - [info] Installing module: node-red-contrib-test-node, version: latest
22 Apr 10:07:39 - [trace] npm.cmd["install","--production","--engine-strict","node-red-contrib-test-node"]
22 Apr 10:07:39 - [debug] npm.cmd install --production --engine-strict node-red-contrib-test-node
22 Apr 10:07:40 - [audit] {"event":"comms.open","level":98,"timestamp":1650614860678}
22 Apr 10:07:40 - [trace] comms.open LwfFsanxxIvMYH1RQW8ICG0ePggbTz1UvYC+tueLn6M=
22 Apr 10:07:45 - [debug] [err] npm
22 Apr 10:07:45 - [debug] [err]  ERR! code E404
22 Apr 10:07:45 - [debug] [err] npm ERR!
22 Apr 10:07:45 - [debug] [err] 404 Not Found - GET https://registry.npmjs.org/node-red-contrib-test-node - Not found
22 Apr 10:07:45 - [debug] [err] npm ERR! 404
22 Apr 10:07:45 - [debug] [err] npm ERR! 404  'node-red-contrib-test-node@latest' is not in the npm registry.
22 Apr 10:07:45 - [debug] [err] npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
22 Apr 10:07:45 - [debug] [err] npm ERR! 404
22 Apr 10:07:45 - [debug] [err] npm ERR! 404 Note that you can also install from a
22 Apr 10:07:45 - [debug] [err] npm ERR! 404 tarball, folder, http url, or git url.
22 Apr 10:07:45 - [debug] [err]
22 Apr 10:07:45 - [debug] [err] npm ERR! A complete log of this run can be found in:
22 Apr 10:07:45 - [debug] [err] npm ERR!     C:\Users\myUser\AppData\Roaming\npm-cache\_logs\2022-04-22T08_07_45_015Z-debug.log
22 Apr 10:07:45 - [debug] rc=1
22 Apr 10:07:45 - [error] Installation of module node-red-contrib-test-node failed: module not found
22 Apr 10:07:45 - [info] Failed to load external modules required by this flow:
22 Apr 10:07:45 - [info]  - node-red-contrib-test-node [404]
22 Apr 10:07:45 - [trace] runtime event: {"id":"runtime-state","payload":{"error":"missing-modules","type":"warning","text":"notification.warnings.missing-modules","modules":[{"module":"node-red-contrib-test-node","error":404}]},"retain":true}

As you have not published your module to npm, then Node-RED cannot install it.

Do not publish your node to npm in its current state - it doesn't meet the naming guidelines in our docs.

Instead, you can manually install it yourself:

  1. Remove your module from nodesDir
  2. In your .node-red directory, run npm install NetHans/node-red-contrib-test-node. This will install your code from your GitHub repository.

I followed your instructions and installed the package manually using the specified command.
At the same time I fixed a small bug in the GitHub repository.

old:

function add(){
    console.log("Hello World");
}

module.exports = add()

new:

function add(){
    console.log("Hello World");
}

module.exports.add = add;

The negative result of the installation can be seen in the log.

Node-RED protocol:

C:\nodejs\nodered222>npm install NetHans/node-red-contrib-test-node
npm WARN saveError ENOENT: no such file or directory, open 'C:\nodejs\nodered222\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\nodejs\nodered222\package.json'
npm WARN nodered222 No description
npm WARN nodered222 No repository field.
npm WARN nodered222 No README data
npm WARN nodered222 No license field.

+ node-red-contrib-test-node@0.0.1
added 1 package and audited 294 packages in 18.006s

31 packages are looking for funding
  run `npm fund` for details

found 1 high severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details

C:\nodejs\nodered222>node-red -s settings.js
22 Apr 10:45:14 - [info]

Welcome to Node-RED
===================

22 Apr 10:45:14 - [info] Node-RED version: v2.2.2
22 Apr 10:45:14 - [info] Node.js  version: v14.6.0
22 Apr 10:45:14 - [info] Windows_NT 10.0.19044 x64 LE
22 Apr 10:45:16 - [info] Loading palette nodes
22 Apr 10:45:16 - [debug] Module: node-red-contrib-test-node 0.0.1 C:\nodejs\nodered222\node_modules\node-red-contrib-test-node
22 Apr 10:45:21 - [info] Settings file  : C:\nodejs\nodered222\settings.js
22 Apr 10:45:21 - [info] Context store  : 'default' [module=memory]
22 Apr 10:45:21 - [info] User directory : C:/nodejs/nodered222/user
22 Apr 10:45:21 - [warn] Projects disabled : editorTheme.projects.enabled=false
22 Apr 10:45:21 - [info] Flows file     : C:\nodejs\nodered222\user\flows.json
22 Apr 10:45:22 - [info] Server now running at http://127.0.0.1:1880/
22 Apr 10:45:22 - [debug] loaded flow revision: 5de98fbfa87c90a857a65e1a892d49b3
22 Apr 10:45:22 - [debug] red/runtime/nodes/credentials.load : no user key present
22 Apr 10:45:22 - [debug] red/runtime/nodes/credentials.load : using default key
22 Apr 10:45:22 - [debug] red/runtime/nodes/credentials.load : keyType=system
22 Apr 10:45:22 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

22 Apr 10:45:22 - [trace] runtime event: {"id":"runtime-state","retain":true}
22 Apr 10:45:22 - [trace] runtime event: {"id":"runtime-deploy","payload":{"revision":"5de98fbfa87c90a857a65e1a892d49b3"},"retain":true}
22 Apr 10:45:22 - [info] Installing module: node-red-contrib-test-node, version: latest
22 Apr 10:45:22 - [trace] npm.cmd["install","--production","--engine-strict","node-red-contrib-test-node"]
22 Apr 10:45:22 - [debug] npm.cmd install --production --engine-strict node-red-contrib-test-node
22 Apr 10:45:28 - [debug] [err] npm
22 Apr 10:45:28 - [debug] [err]  ERR! code E404
22 Apr 10:45:28 - [debug] [err] npm
22 Apr 10:45:28 - [debug] [err] ERR! 404 Not Found - GET https://registry.npmjs.org/node-red-contrib-test-node - Not found
22 Apr 10:45:28 - [debug] [err] npm ERR! 404
22 Apr 10:45:28 - [debug] [err] npm ERR! 404  'node-red-contrib-test-node@latest' is not in the npm registry.
22 Apr 10:45:28 - [debug] [err] npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
22 Apr 10:45:28 - [debug] [err] npm ERR! 404
22 Apr 10:45:28 - [debug] [err] npm ERR! 404 Note that you can also install from a
22 Apr 10:45:28 - [debug] [err] npm
22 Apr 10:45:28 - [debug] [err]  ERR! 404 tarball, folder, http url, or git url.
22 Apr 10:45:29 - [debug] [err]
22 Apr 10:45:29 - [debug] [err] npm ERR! A complete log of this run can be found in:
22 Apr 10:45:29 - [debug] [err] npm ERR!     C:\Users\myUser\AppData\Roaming\npm-cache\_logs\2022-04-22T08_45_28_994Z-debug.log
22 Apr 10:45:29 - [debug] rc=1
22 Apr 10:45:29 - [error] Installation of module node-red-contrib-test-node failed: module not found
22 Apr 10:45:29 - [info] Failed to load external modules required by this flow:
22 Apr 10:45:29 - [info]  - node-red-contrib-test-node [404]
22 Apr 10:45:29 - [trace] runtime event: {"id":"runtime-state","payload":{"error":"missing-modules","type":"warning","text":"notification.warnings.missing-modules","modules":[{"module":"node-red-contrib-test-node","error":404}]},"retain":true}
22 Apr 10:46:48 - [trace] utils.writeFile - copied C:\nodejs\nodered222\user\flows.json TO C:\nodejs\nodered222\user\.flows.json.backup
22 Apr 10:46:48 - [trace] utils.writeFile - written content to C:\nodejs\nodered222\user\flows.json.$$$
22 Apr 10:46:48 - [trace] utils.writeFile - renamed C:\nodejs\nodered222\user\flows.json.$$$ to C:\nodejs\nodered222\user\flows.json
22 Apr 10:46:48 - [debug] saved flow revision: fe3b491de531dccc661b08f7d8be7017
22 Apr 10:46:48 - [info] Stopping flows
22 Apr 10:46:48 - [info] Stopped flows
22 Apr 10:46:48 - [info] Installing module: node-red-contrib-test-node, version: latest
22 Apr 10:46:48 - [trace] npm.cmd["install","--production","--engine-strict","node-red-contrib-test-node"]
22 Apr 10:46:48 - [debug] npm.cmd install --production --engine-strict node-red-contrib-test-node
22 Apr 10:46:54 - [debug] [err] npm
22 Apr 10:46:54 - [debug] [err]  ERR! code E404
22 Apr 10:46:54 - [debug] [err] npm ERR!
22 Apr 10:46:54 - [debug] [err] 404 Not Found - GET https://registry.npmjs.org/node-red-contrib-test-node - Not found
22 Apr 10:46:54 - [debug] [err] npm ERR! 404
22 Apr 10:46:54 - [debug] [err] npm ERR! 404  'node-red-contrib-test-node@latest' is not in the npm registry.
22 Apr 10:46:54 - [debug] [err] npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
22 Apr 10:46:54 - [debug] [err] npm ERR! 404
22 Apr 10:46:54 - [debug] [err] npm ERR! 404 Note that you can also install from a
22 Apr 10:46:54 - [debug] [err] npm
22 Apr 10:46:54 - [debug] [err]  ERR! 404 tarball, folder, http url, or git url.
22 Apr 10:46:54 - [debug] [err]
22 Apr 10:46:54 - [debug] [err] npm ERR! A complete log of this run can be found in:
22 Apr 10:46:54 - [debug] [err] npm ERR!     C:\Users\myUser\AppData\Roaming\npm-cache\_logs\2022-04-22T08_46_54_641Z-debug.log
22 Apr 10:46:54 - [debug] rc=1
22 Apr 10:46:54 - [error] Installation of module node-red-contrib-test-node failed: module not found
22 Apr 10:46:54 - [info] Failed to load external modules required by this flow:
22 Apr 10:46:54 - [info]  - node-red-contrib-test-node [404]
22 Apr 10:46:54 - [trace] runtime event: {"id":"runtime-state","payload":{"error":"missing-modules","type":"warning","text":"notification.warnings.missing-modules","modules":[{"module":"node-red-contrib-test-node","error":404}]},"retain":true}
22 Apr 10:46:54 - [trace] runtime event: {"id":"runtime-deploy","payload":{"revision":"fe3b491de531dccc661b08f7d8be7017"},"retain":true}
22 Apr 10:47:17 - [trace] comms.open sgYIoOBLjN1l5k5QznAqQCyV//7w6z+n+D36TYUjt8w=

flow:

[
    {
        "id": "66085ac6a9ed6635",
        "type": "inject",
        "z": "f3cca6aa798dbc3d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 300,
        "y": 300,
        "wires": [
            [
                "37e18f80cfa719e0"
            ]
        ]
    },
    {
        "id": "942339b4ab08904c",
        "type": "debug",
        "z": "f3cca6aa798dbc3d",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 750,
        "y": 300,
        "wires": []
    },
    {
        "id": "37e18f80cfa719e0",
        "type": "node-red-contrib-test-node",
        "z": "f3cca6aa798dbc3d",
        "name": "",
        "x": 450,
        "y": 300,
        "wires": [
            [
                "fd315bca4a9ec337"
            ]
        ]
    },
    {
        "id": "fd315bca4a9ec337",
        "type": "function",
        "z": "f3cca6aa798dbc3d",
        "name": "",
        "func": "nodeRedContribTestNode.add();\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [
            {
                "var": "nodeRedContribTestNode",
                "module": "node-red-contrib-test-node"
            }
        ],
        "x": 600,
        "y": 300,
        "wires": [
            [
                "942339b4ab08904c"
            ]
        ]
    }
]

package.json after installation

{
  "_from": "github:NetHans/node-red-contrib-test-node",
  "_id": "node-red-contrib-test-node@0.0.1",
  "_inBundle": false,
  "_integrity": "",
  "_location": "/node-red-contrib-test-node",
  "_phantomChildren": {},
  "_requested": {
    "type": "git",
    "raw": "NetHans/node-red-contrib-test-node",
    "rawSpec": "NetHans/node-red-contrib-test-node",
    "saveSpec": "github:NetHans/node-red-contrib-test-node",
    "fetchSpec": null,
    "gitCommittish": null
  },
  "_requiredBy": [
    "#USER",
    "/"
  ],
  "_resolved": "github:NetHans/node-red-contrib-test-node#fa8494b0094502e39a6fd9ef1550d05d8d950f2d",
  "_spec": "NetHans/node-red-contrib-test-node",
  "_where": "C:\\nodejs\\nodered222",
  "bundleDependencies": false,
  "dependencies": {},
  "deprecated": false,
  "description": "Test Node with library",
  "keywords": [
    "node-red",
    "test"
  ],
  "license": "",
  "main": "TestLib.js",
  "name": "node-red-contrib-test-node",
  "node-red": {
    "nodes": {
      "NodeRedContribTestNodeHandler": "TestNode.js"
    }
  },
  "version": "0.0.1"
}

@knolleary @NetHans I can confirm the changes Nick made work. What i did...

  1. Run node-red with the changes Nick made (actually I ran the fix-import-node-library branch)
  2. Ran npm install NetHans/node-red-contrib-test-node
  3. Added an import entry in the function node to node-red-contrib-test-node
  4. called nodeRedContribTestNode.add() in the function.

image

image

1 Like

My guess here is your node-red folder is NOT 'C:\nodejs\nodered222\'

When you run node-red, the start up log tells you where your node-red folder is...

So in my case, I did...

cd c:\users\Stephen\node-red-1881
npm install NetHans/node-red-contrib-test-node
1 Like

@Steve-Mcl: Thanks for pointing out that I was in the wrong directory.

I have reinstalled the module in the userDir. This has worked. I can now also confirm that the customizations from @knolleary work.

Thanks to all involved for the quick solving of my problem.

@knolleary: Will it be possible in a future release that libraries can also be loaded from the nodesDir?