简体   繁体   中英

How to use npm link with git repositories only accessible with ssh

I'm trying to develop a node app with some supporting libraries. The projects all live in private repositories that are accessed via ssh. Username and password authentication are not an option.

So far I've been adding the git repository url to the package.json

"dependencies": {
  "my-library":"git+ssh://git@repo-url:repo-name.git#master"
},

This isn't great as it doesn't lead to reproducible builds and it means that to develop client code and the library at the same time requires pushing for every little change.

npm link appears to be ideal for solving this but running npm link in the library directory, produces the following error:

~/mylibrary$ npm link
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/mockelganger'
etc etc

Fair enough, it's trying to modify a system-global location.

~/mylibrary$ sudo npm link
|it@repo-url's password: -

Where that "|" obscuring the "g" is an animated spinner. I've determined that this is what git does when I try to access a repository as route; for whatever reason it fails to see my ~/.ssh/id_rsa or my ssh agent.

I suppose I could possibly solve this by figuring out how to run an ssh-agent for root but it just doesn't make sense to me that npm link even needs to read from git. It's modifying the configuration of only my computer so it why is it accessing the network? This makes me think I'm doing something else wrong.

The solution is to change the npm prefix to somewhere that doesn't require root permissions.

npm config set prefix ~/npm

Remember to add ~/npm to the path if your installing executables such as CoffeeScript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM