nebrius / raspi-io

An IO plugin for Johnny-Five that provides support for the Raspberry Pi
MIT License
545 stars 63 forks source link

Error: Cannot find module 'raspi-io' #101

Closed ahmadasadi closed 6 years ago

ahmadasadi commented 6 years ago

hi i've installed johnny5 and raspi-io but when i use johnny5 in node-red ,it says "Error: Cannot find module 'raspi-io'" and can not connected. here is the problem ( pls help me): Stop Node-RED pi@raspberrypi:~ $ npm install johnny-five raspi-io npm WARN saveError ENOENT: no such file or directory, open '/home/pi/package.json' npm WARN enoent ENOENT: no such file or directory, open '/home/pi/package.json' npm WARN pi No description npm WARN pi No repository field. npm WARN pi No README data npm WARN pi No license field.

pi@raspberrypi:~ $ node-red-start

Start Node-RED

Once Node-RED has started, point a browser at http://192.168.1.5: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. 12 Feb 21:09:00 - [warn] [johnny5:5a8b567d.59b738] Error: Cannot find module 'raspi-io'

monteslu commented 6 years ago

@ahmadasadi while you do install raspi-io as a the pi user, you have to actually run it as the root user: https://github.com/nebrius/raspi-io#system-requirements

nebrius commented 6 years ago

I'm admittedly not very familiar with node-red. Where is your node-red project stored at?

Looking at the error message, these lines pop out at me:

npm WARN saveError ENOENT: no such file or directory, open '/home/pi/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/pi/package.json'

This tells me that you tried to run npm install johnny-five raspi-io from /home/pi, but your project code is located somewhere else. The npm command needs to be run from the root fo your project folder, where the package.json file is located. From this error code, it's implied to me that it's somewhere other than /home/pi.

ahmadasadi commented 6 years ago

sorry i think these lines means that raspi-io has been installed. am i right?

ahmadasadi commented 6 years ago

package.json is in pi@raspberrypi:~/.node-red and i run npm command as a root user in the following and the result is these lines: pi@raspberrypi:~ $ cd .node-red pi@raspberrypi:~/.node-red $ ls flows_raspberrypi_cred.json package.json settings.js.bak flows_raspberrypi.json package-lock.json settings.js.save lib projects node_modules settings.js pi@raspberrypi:~/.node-red $ sudo npm install johnny-five raspi-io

serialport@6.0.5 install /home/pi/.node-red/node_modules/serialport prebuild-install || node-gyp rebuild

sh: 1: prebuild-install: not found gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/6.12.3" gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp" gyp WARN EACCES user "root" does not have permission to access the dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp/6.12.3" gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp" gyp WARN EACCES user "root" does not have permission to access the dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp/6.12.3" gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp" gyp WARN EACCES user "root" does not have permission to access the dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp/6.12.3" gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp" gyp WARN EACCES user "root" does not have permission to access the dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp/6.12.3" gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp" gyp WARN EACCES user "root" does not have permission to access the dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp/6.12.3" gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp" gyp WARN EACCES user "root" does not have permission to access the dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp/6.12.3" gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp" gyp WARN EACCES user "root" does not have permission to access the dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp/6.12.3" gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp" gyp WARN EACCES user "root" does not have permission to access the dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp/6.12.3" gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp" gyp WARN EACCES user "root" does not have permission to access the dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp/6.12.3" gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/.node-red/node_modules/serialport/.node-gyp"

and above lines results frequently and non stopping

what can i do next ? thanks a lot

nebrius commented 6 years ago

Hmm, for some reason that folder is owned by a different user. Can you try running:

sudo chmod -R 775  /home/pi/.node-red/
ahmadasadi commented 6 years ago

pi@raspberrypi:~ $ sudo chmod -R 775 /home/pi/.node-red/

pi@raspberrypi:~/.node-red $ sudo npm install johnny-five raspi-io [sudo] password for pi: npm WARN node-red-project@0.0.1 No repository field. npm WARN node-red-project@0.0.1 No license field.

Start Node-RED

Once Node-RED has started, point a browser at http://217.218.0.123: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.. 13 Feb 09:46:51 - [info] Welcome to Node-RED

13 Feb 09:46:51 - [info] Node-RED version: v0.17.5 13 Feb 09:46:51 - [info] Node.js version: v6.12.3 13 Feb 09:46:51 - [info] Linux 4.9.73-v7+ arm LE 13 Feb 09:46:54 - [info] Loading palette nodes 13 Feb 09:47:15 - [warn] ------------------------------------------------------ 13 Feb 09:47:15 - [warn] [serialport] Error: Module version mismatch. Expected 48, got 14. 13 Feb 09:47:15 - [warn] [facebook] ReferenceError: res is not defined (line:16) 13 Feb 09:47:15 - [warn] ------------------------------------------------------ 13 Feb 09:47:15 - [info] Settings file : /root/.node-red/settings.js 13 Feb 09:47:15 - [info] User directory : /root/.node-red 13 Feb 09:47:15 - [info] Flows file : /root/.node-red/flows_raspberrypi.json 13 Feb 09:47:15 - [info] Server now running at http://127.0.0.1:1880/ 13 Feb 09:47:15 - [info] Starting flows 13 Feb 09:47:15 - [info] [nodebot:90ff9813.035188] error loading io class 13 Feb 09:47:15 - [info] Started flows 13 Feb 09:47:15 - [warn] [johnny5:5a8b567d.59b738] Error: Cannot find module 'raspi-io'

i did it but problem not solved thanks for your help

ahmadasadi commented 6 years ago

hi my raspbian version is :+1: pi@raspberrypi:~ $ lsb_release -a No LSB modules are available. Distributor ID: Raspbian Description: Raspbian GNU/Linux 9.3 (stretch) Release: 9.3 is it ok for installing johnny-five and raspi-io?

fivdi commented 6 years ago

Yes, Raspbian Stretch is ok for Johnny-Five and Raspi-IO.

The output posted above shows the following error:

13 Feb 09:47:15 - [warn] [serialport] Error: Module version mismatch. Expected 48, got 14.

This means that Node.js v0.11 or v0.12 is being used at runtime but Node.js v6 is expected.

The Node.js module version numbers for the different versions of Node.js can be found at https://nodejs.org/en/download/releases/

Raspi-IO itself requires Node.js v4.0.0 or higher.

It looks like the Raspberry Pi is not configured correctly. Perhaps the users root and pi are accessing different versions of Node.js.

What's the output of the following two commands?

node -v
sudo node -v
ahmadasadi commented 6 years ago

hi thanks a lot answer is :+1: pi@raspberrypi:~ $ node -v v6.12.3 pi@raspberrypi:~ $ sudo node -v [sudo] password for pi: v6.12.3

ahmadasadi commented 6 years ago

sorry the thumb sign came by mistake excuse me i mean answer is :

fivdi commented 6 years ago

Hmm, I don't understand what's happening yet.

What's the output of the the following commands?

nodejs -v
sudo nodejs -v
nebrius commented 6 years ago

There's definitely some sort of Node.js version mismatch at play, but what I can't say specifically. From the output of node -v and sudo node -v it looks like pathing is set up correctly there. @monteslu do you know if node-red ships its own Node.js runtime?

Another thing I see: you shouldn't use sudo with npm install. Instead, you should run npm install johnny-five raspi-io without the sudo part. Can you try without sudo and see if that helps?

nebrius commented 6 years ago

I'm closing this due to inactivity. Please feel free to reopen if you're still having issues.