Could not locate the bindings file

Hi all

I followed the online tutorial to create your first node. It worked exactly as expected.

I then tried to create my own node and everything goes well until I try to use it within node-red. The only difference between the example and my code is, that I have a dependency on sensit-payload.

When I use the node, I get the following error:
[error] [sensit-decoder:c6cbc5fe.014f18] Error: Could not locate the bindings file. Tried:.....

When I create a function within node-red with the sam function code in my node js file, It works fine, with no errors.

Can you maybe assist me in resolving the issue?

Regards
Morne Supra

It would help to give us the full error and also perhaps a pointer to your code on GitHub.

You will likely need to add some extra console.log statements to find out where in your code this is being triggered.

Hi all. Please find the error below and the git repo, bitbucket.org:supragroup/sensit-decode.git:
0|integrem | 15 Jun 09:44:57 - [error] [sensit-decoder:7bdcbd87.7800e4] Error: Could not locate the bindings file. Tried:
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/build/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/build/Debug/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/build/Release/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/out/Debug/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/Debug/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/out/Release/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/Release/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/build/default/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/compiled/8.16.0/linux/x64/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/addon-build/release/install-root/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/addon-build/debug/install-root/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/addon-build/default/install-root/sensit_payload_lib.node
0|integrem | → /root/sensit-decoder/node_modules/sensit-payload/lib/binding/node-v57-linux-x64/sensit_payload_lib.node

Regards
Morne

Hi
Update on git repo:
https://bitbucket.org/supragroup/sensit-decode/src/master/

There would appear to be some errors in this code:

module.exports = function(RED) {
    function SensitDecoderNode(config) {
        RED.nodes.createNode(this,config);
        var node = this;
        node.on('input', function(msg) {
	    const sensitPayload = require('sensit-payload');
            msg.payload = sensitPayload.parse(msg.payload);
            node.send(msg);
        });
    }
    RED.nodes.registerType("sensit-decoder",SensitDecoderNode);
}

For 1, you shouldn't put a "require" in the middle of your code. It should go at the top. Indeed, it should go outside the module.exports.

Then the code indentation makes it hard to follow.

Finally, this error is a problem with the 'sensit-payload' package as far as I can tell.

Hi @TotallyInformation. I moved the require to outside the module.exports, but then the node won't register.

When I place it after RED.nodes.createNode(), I get no errors, but also no response:
module.exports = function(RED) {
function SensitDecoderNode(config) {
RED.nodes.createNode(this,config);
const sensitPayload = require('sensit-payload');
var node = this;
node.on('input', function(msg) {
msg.payload = sensitPayload.parse(msg.payload);
node.send(msg);
});
}
RED.nodes.registerType("sensit-decoder",SensitDecoderNode);
}

When I remove it completely, as expected, I get "ReferenceError: sensitPayload is not defined" inside node-red debug.

When I use the sensit-payload package within a function inside node-red, it works fine.

I am definitely not an expert developer and this is my first attempt at trying to write a node, so it is a learning curve for me.

Regards
Morne

Please wrap code in back-ticks so that it is more easily read.

const sensitPayload = require('sensit-payload');

module.exports = function(RED) {
    function SensitDecoderNode(config) {
        RED.nodes.createNode(this,config);

        var node = this;

        node.on('input', function(msg) {
            msg.payload = sensitPayload.parse(msg.payload);
            node.send(msg);
        });
    }

    RED.nodes.registerType("sensit-decoder",SensitDecoderNode);
}

The above should work as long as sensitPayload.parse(msg.payload) is valid.

As I said before, I think this is an issue with 'sensit-payload'.

If you look at my node-red-contrib-uibuilder node, especially the v2 branch you should see that I've used the structure above and it works just fine.

I would also recommend using a code editor with ESLint or JSLint to help you with the layout of your code and avoid mixing quote types as the above code does (' and "). While this isn't an error, it is harder to read which makes identifying errors harder.

@TotallyInformation, thank you very much for your assistance, patience and guidance.

It looks like there might be an issue with sensit-payload, as it is still not working.

I will try creating a node with another package.

Regards
Morne

A quick look at the code shows me that the bindings file is a C library that installing the package should automatically create for you.

I'm thinking that you either didn't completely install the package or it is installed in the wrong place.

Does your node's package.json include a reference to sensit-payload and did you run npm install to get it installed? Did you get any errors from the compilation?

Might be best to delete the package folder and start again.

Hi @TotallyInformation. After I replied earlier, I actually went back to my nodered directory and did a manual install of sensit-payload via npm. After that the node worked as expected.

There is a reference in the package.json, but I suspect somewhere along the line, the package did not install properly.

Thanks for all your help.

Regards
Morne