Error: cannot find module mqtt

Sorry if the question could be stupid, but I don't know how to solve this.
I recently upgraded my OS to new Lubuntu version 20.04 and I lost my files.
I re-installed Node-RED and now I don't have 1.0.5, but 1.0.6 version.
The problem is that now when I use my custom node that use MQTT javascript library, I get the error : cannot find module mqtt.
My node-red was installed into /usr/local/lib/node_modules/node-red/ and the .nod-red folder into /home/USER.
Why now when I use a custom node, I get this error? Before these changes all worked perfectly.

EDIT: Also if I install mqtt globally, I get the same error.

Thanks.

Is that a javascript library or a nodejs module?
If it is a javascript library where does it come from?

1 Like

What do you see if you run, from your .node-red folder
npm list mqtt
What version of nodejs are you running?
node -v

1 Like

Inside .node-red folder the result is: └── mqtt@3.0.0
node -v output: v10.19.0

Where/how is your custom node installed? Does it list mqtt as a dependency in its package.json?

1 Like

/home/edoardottt/Desktop/my-Node-RED/custom/node-red-contrib-custom-folder-example
This is the location, before starting node-red, i type npm install {this_path} inside .node-red folder and the output is ok, all right.
No, there isn't the dependency...:confused: but in node-red1.0.5 it worked. I'm adding this.

I notice that node red pulls in version 2.18.8, I don't know whether it is significant that it does not use v3. Have you now got multiple versions installed? What does
npm list -g mqtt
show? However Nick is right. You should specify a dependency in your custom node, then it would install the version you require automatically.

1 Like

Now it's working. But I think i'm doing something wrong. Now in every custom node it downloads a big node_modules folder...How is it possible? It's a waste of space. If it depends on a specific module why not have a single point of shared node_modules?
Obviously, I downloaded mqtt with global mode enabled, but why it has to download the same module n times?

How did you install nodejs and npm? npm used to do that I think, but now it flattens things out so it shouldn't happen. I think.
What version of npm are you running?
npm -v

1 Like

version 6.14.4

You didn't tell us that bit.

1 Like

Sorry, both by apt. sudo apt install nodejs & npm. Both are on their newest version.

Actually 12.x is the newest LTS version and the bleeding edge (not recommended) is 13.x, but 10.x is ok. I don't know whether the versions from the Lubuntu repository are ok, I use the recommended install script for Ubuntu which installs from the nodesource repository. However I have no reason to think that the versions you have should not be ok. Someone more knowledgeable would have to comment.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.