Error: Cannot find module 'i2c-bus'

#1

New installion of node-red, but get the following error when trying to start it.

pi@jrbWork:~ $ node-red-start

Start Node-RED

Once Node-RED has started, point a browser at http://192.168.1.201:1880
On Pi Node-RED works better with the Firefox or Chrome browser

Use node-red-stop to stop Node-RED
Use node-red-start to start Node-RED again
Use node-red-log to view the recent log output
Use sudo systemctl enable nodered.service to autostart Node-RED at every boot
Use sudo systemctl disable nodered.service to disable autostart on boot

To find more nodes and example flows - go to http://flows.nodered.org

Starting as a systemd service.
Started Node-RED graphical event wiring tool.
Error loading settings file: /home/pi/.node-red/settings.js
Error: Cannot find module 'i2c-bus'

#2

You say it is a new installation, but did you already have /home/pi/.node-red/settings.js in place with any changes in?

Have a look in that file for any reference to i2c-bus.

#3

Thanks for your reply, here is the settings.js file.

/**

**/

var fs = require("fs");

var i2c = require("i2c-bus");

var mySettings;

try {

mySettings = require("/home/pi/.node-red/redvars.js");

} catch(err) {

mySettings = {};

}

module.exports = {

uiPort: process.env.PORT || 1880,

mqttReconnectTime: 15000,

serialReconnectTime: 15000,

debugMaxLength: 1000,

flowFile: 'flows.json',

flowFilePretty: true,

httpStatic: '/home/pi/.node-red/public',

functionGlobalContext: {

os:require('os'),

moment:require('moment'),

fs:require('fs'),

	i2c:require('i2c-bus'),

mySettings:mySettings

},

logging: {

console: {

level: "info",

metrics: false,

audit: false

}

},

adminAuth: { type: "credentials", users: [{ username: "", password: "", permissions: "*" }] },

httpNodeAuth: {user:"admin", pass:""},

editorTheme: { projects: { enabled: false }

}

// By default, credentials are encrypted in storage using a generated key. To

// specify your own secret, set the following property.

// If you want to disable encryption of credentials, set this property to false.

// Note: once you set this property, do not change it - doing so will prevent

// node-red from being able to decrypt your existing credentials and they will be

// lost.

//credentialSecret: "a-secret-key",

//https: {

// key: fs.readFileSync('privatekey.pem'),

// cert: fs.readFileSync('certificate.pem')

//},

//requireHttps: tr

#4

and i did install peter scargills script before testing.

John

#5

If you really didn't have a settings.js file before (for example having installed Node-RED on that machine before), then you need to go to Pete Scargill's website and highlight the issue to him, as it would appear he is using a modified settings.js.

Try comparing that file against the "Originale" one.

Personally I would delete everything in the .node-red directory and start again, to confirm that the settings.js file is the from the install rather than an old one.

#6

Please read this post on sharing code on the forum: How to share code or flow json

You can see at the top of the settings file it has var i2c = require("i2c-bus"); - which is where it is trying to load the i2c-bus module. That is not part of the default settings file.

...

I see @ukmoose has also replied - I echo his comments.

#7

Thanks for your help.

I'm going to start over and see if i can find out where it comes from.

john

#8

ok, thanks - i replied to ukmoose and i am going to start fresh and see where it comes from. Is it possible that installing a node via the palette manager or by npm install can modify settings.js?

john

#9

If you are starting again then delete the .node-red folder.
You said you used Peter Scargills script, which script is that? The recommended way of installing node red on a pi is here
https://nodered.org/docs/hardware/raspberrypi

#10

Hi Colin,

you can see the script here: https://tech.scargill.net/the-script/#comment-46288

Easy way of installing a bunch of stuff including npm, nodered, sqlite,apache etc etc.

Perhaps that is the problem and i'm going to start with a new rpi stretch installation and see how it goes. I'll use the recommended node-red install procedure and try and install some nodes that I have had problems with before - basically crashed node red and had to start over again. I'll report when i have finished and hopefully tracked down the issue.

John

#11

No, settings.js is not modified by installing nodes

#12

Thanks for all the help Nick (and others),

I installed node-red and npm as you suggested, and then scargills script afterwards omitting the npm and node-red part of the installation and all worked perfectly.

I know a lot of people are using the scargill script and I'll post this info on his blog also.

Just a quick question, the node-red-node-email node gets installed during the node-red installation as a default. There is a newer version available as the palette manager says there is an update, but it is not updatable from the palette manager as it is installed globally. It has to be uninstalled and reinstalled to work. Little bit of a pain.

Thanks again

John

#13

That’s something else to mention to Pete, search the forum for how to fix its come up several times.

#14

I'll do that - thank you.

john

#15

Yes. The default email node is in line with the core Node-RED in that it still works on nodejs v4. We will update to the later email node as soon as we drop v4 support in our next release