Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add further documentation to npm link #69

Open
LeLunZ opened this issue May 17, 2024 · 12 comments
Open

Add further documentation to npm link #69

LeLunZ opened this issue May 17, 2024 · 12 comments

Comments

@LeLunZ
Copy link

LeLunZ commented May 17, 2024

From the README.md it seems one should run npm link while he is in the project folder. (as its directly after building the project and its never specified to change directory)

But from the experience I just had, you need to run it from the homebridge path (/var/lib/homebridge) like that npm link /path/to/project

@luis-godinez
Copy link

@LeLunZ thanks for flagging this! I was having similar problems.

@gdavids57
Copy link

Further to this issue, shouldn't one use "hb-service link" rather than npm link?

@brianhackel
Copy link

brianhackel commented Sep 17, 2024

i think i'm having issues related to this. in the past, i set up a homebridge server which included an npm install and i could clone a repo and do npm install && npm link and it would load the plugin after a homebridge restart.
Now i'm setting up a new server and installed homebridge using these instructions exactly. it would seem that homebridge now comes with node and npm bundled (in /opt/homebridge/bin). Thus, npm link gives "command not found."
i've tried using sudo hb-service link from my cloned plugin directory, but then i get EACCES permissions errors. fixing up the permissions doesn't seem to help, so i tried running homebridge as root (which is not something i should NOT have to do to get this to work). the plugin directory was at least now recognized, but the issue is that its dependent libraries are not installed (having not done npm install to grab all the dependencies like before, since npm is now packaged with homebridge).
what is the proper procedure now with hb-service to do plugin development?

@brianhackel
Copy link

so it looks like maybe i have to use the hb-shell to install the dependencies. this still didn't fix the issue i had with needing to run as root though in order for it to have permissions to follow the symlink

@brianhackel
Copy link

if i moved the directory to the /home/homebridge/ directory and set the permissions and then did the npm link from the hb-shell, it appears to now be working without root. curious that it didn't work when the permissions were the same and the directory resided in /home/

@luis-godinez
Copy link

luis-godinez commented Sep 17, 2024

On a raspberry pi running the homebridge OS, I use the following to link the custom custom plugin.
The gist is run the npm link command from the homebridge directory and specify the repo disk path.

Download & build custom plugin:

cd /home/
git clone https://github.com/luis-godinez/OpenSauna.git
cd OpenSauna/
npm install
npm run build

Link NPM Package to Homebridge:

cd /var/lib/homebridge/
npm link /home/OpenSauna

@brianhackel
Copy link

brianhackel commented Sep 17, 2024

cd /var/lib/homebridge/
npm link /home/opensauna/OpenSauna

and so you didn't have to mess with permissions on /home/opensauna/OpenSauna? I did basically the same thing, but homebridge (running under the homebridge user) was throwing EACCES permissions errors when it tried to load the plugin at service start. moving the repo under /home/homebridge and setting the owner as homebridge:homebridge solve this, but it means i'll have to either make my user a member of the homebridge group, or i'll have to do my plugin development as root and make sure to change the ownership on any new files i create.
Also, the other missing piece was having to use hb-shell because npm and node are now bundled with hb-service if you install directly from apt.

@LeLunZ
Copy link
Author

LeLunZ commented Sep 17, 2024

@brianhackel you need to do this with the homebridge user account/permissions or from the terminal provided in the web-ui.

There I don’t have any permission errors.

@luis-godinez
Copy link

luis-godinez commented Sep 17, 2024

cd /var/lib/homebridge/
npm link /home/OpenSauna

and so you didn't have to mess with permissions on /home/opensauna/OpenSauna? I did basically the same thing, but homebridge (running under the homebridge user) was throwing EACCES permissions errors when it tried to load the plugin at service start. moving the repo under /home/homebridge and setting the owner as homebridge:homebridge solve this, but it means i'll have to either make my user a member of the homebridge group, or i'll have to do my plugin development as root and make sure to change the ownership on any new files i create. Also, the other missing piece was having to use hb-shell because npm and node are now bundled with hb-service if you install directly from apt.

I used the default pi:raspberry login on the Homebridge Pi image (docs), no settings or permissions were changed.

I did create symlinks for npm and node to make my life easier:

Add symlinks:

sudo ln -s /opt/homebridge/bin/node /usr/local/bin/node
sudo ln -s /opt/homebridge/bin/npm /usr/local/bin/npm

@brianhackel
Copy link

I did create symlinks for npm and node to make my life easier:

@luis-godinez, good call on the symlinks.

Thanks all!
Maybe if i get motivated, i'll submit a PR to update the documentation for others.

@Feilner
Copy link

Feilner commented Nov 16, 2024

Some additional comments also for for others wo have the same issues.

The symbolic links to use nodejs and npm from the homebridge installation is a very good idea and worked for me;

sudo ln -s /opt/homebridge/bin/node /usr/local/bin/node
sudo ln -s /opt/homebridge/bin/npm /usr/local/bin/npm

The generation of the symbolic link with npm link did not work out for me because it generates a relative link instead i used

cd /var/lib/homebridge/node_modules

sudo ln -s /home/OpenSauna homebridge-openspa

Also the dependency to the package has to be added into the package.json of homebridge e.g.
sudo nano /var/lib/homebridge/package.json

And finally the config to the config.json

@d0n13
Copy link

d0n13 commented Dec 1, 2024

And also note you need to turn off this flag --strict-plugin-resolution which is documented on forums but when changing the startup script to remove it's still on. You have to do it from the UI where it's called "Homebridge 'Insecure' Mode"

I think the documentation should be improved and would gladly help if I can find a clean way to actually get everything to work without a load of bash gymnastics :)

The above is helpful, didn't think of doing the linking of node and npm...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants