Error: Cannot find module 'i2c-bus'


#1

We hit a weird error(Error: Cannot find module ‘i2c-bus’
) even we have done" npm install i2c-bus", we have also checked npm list as follows:

$npm list|grep i2c-bus
├─┬ i2c-bus@3.2.0
│ ├─┬ i2c-bus@1.2.5
│ ├── i2c-bus@3.2.0 deduped
any advice would be appreciated.

Error: Cannot find module 'i2c-bus'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (/home/pi/Dexter/GrovePi/Software/NodeJS/libs/grovepi.js:2:19)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (/home/pi/Dexter/GrovePi/Software/NodeJS/libs/sensors/base/sensor.js:3:20)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)


#2

Hi @joeyangx,

Did you run into any issue when you ran npm install i2c-bus? I see that the package corresponds with that command you ran https://www.npmjs.com/package/i2c-bus, which is what we want.

Might be an idea to remove the package and install it again. And when you install it, make sure you have an internet connection. Because, otherwise, it wouldn’t make any sense not to work.

Thank you!


#3

@RobertLucian ,Thans for your prompt response, I have install/uninstall “npm install i2c-bus” several time, we did have internet during installation, please take a look at the following steps, we run it on pi3, node version 10.7.0, any prompt advice would be appreciated:

pi@s08:~/workspace/rapiro-iotf $ npm uninstall i2c-bus
npm WARN rapiro-iotf@0.0.0 No description
npm WARN rapiro-iotf@0.0.0 No repository field.

audited 3085 packages in 16.412s
found 10 vulnerabilities (8 moderate, 2 critical)
run npm audit fix to fix them, or npm audit for details
pi@s08:~/workspace/rapiro-iotf $ npm install i2c-bus

i2c-bus@3.2.0 install /home/pi/workspace/rapiro-iotf/node_modules/raspi-i2c/node_modules/i2c-bus
node-gyp rebuild

make: Entering directory ‘/home/pi/workspace/rapiro-iotf/node_modules/raspi-i2c/node_modules/i2c-bus/build’
CXX(target) Release/obj.target/i2c/src/i2c.o
SOLINK_MODULE(target) Release/obj.target/i2c.node
COPY Release/i2c.node
make: Leaving directory ‘/home/pi/workspace/rapiro-iotf/node_modules/raspi-i2c/node_modules/i2c-bus/build’

i2c-bus@4.0.0 install /home/pi/workspace/rapiro-iotf/node_modules/i2c-bus
node-gyp rebuild

make: Entering directory ‘/home/pi/workspace/rapiro-iotf/node_modules/i2c-bus/build’
CXX(target) Release/obj.target/i2c/src/i2c.o
SOLINK_MODULE(target) Release/obj.target/i2c.node
COPY Release/i2c.node
make: Leaving directory ‘/home/pi/workspace/rapiro-iotf/node_modules/i2c-bus/build’
npm WARN rapiro-iotf@0.0.0 No description
npm WARN rapiro-iotf@0.0.0 No repository field.

  • i2c-bus@4.0.0
    added 1 package from 1 contributor, updated 1 package and audited 3088 packages in 45.911s
    found 10 vulnerabilities (8 moderate, 2 critical)
    run npm audit fix to fix them, or npm audit for details

#4

any update would be appreciated…


#5

our node.js code is as follows:

const SerialPort = require(‘serialport’);
const parsers = SerialPort.parsers;
const parser = new parsers.Readline({
delimiter: ‘\r\n’
});
const port = new SerialPort(’/dev/ttys0’, {
baudRate: 57600
});


#6

Hi @joeyangx,

I guess starting with a fresh image of Raspbian For Robots would be a good thing to do. Again, on mine I can install it and use it just fine.

Thank you!