Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install dependencies with npm from private gitlab repo

Tags:

git

npm

reactjs

I'm trying to install a package that exists on our private repo. The goal is to share the repo with a partner, but I need to make sure they can install it. In theory, it should work, but none of the documented solutions are working for me

I've tried adding the package to the package.json file

"dependencies": {
    "package_name": "git+https://<deploy-token-name>:<deploy-token>@gitlab.domain.com/group/repo.git"
}

And then installing with npm but it seems to fail on the deploy token, but it's hard to say because the log isn't very helpful and then our whole gitlab deployment goes down for a moment #fun

29 error
29 error undefined
29 error exited with error code: 128

I've also tried with a private access token

"package-name": "https://oauth2:<access-token>@gitlab.domain.com/group/repo.git"

This results in an actual error that I can understand, except the error is saying there isn't a package.json in the repository, but there most certainly is

npm ERR! package.json Non-registry package missing package.json: package-name@https://oauth2:<access-token>@gitlab.domain.com/group/repo.git.
npm ERR! package.json npm can't find a package.json file in your current directory.

I've tried with ssh (with a ssh key setup that works for commits etc)

git+ssh://[email protected]:my-project/my-repo#my-branch

And that results in an error

npm ERR! premature close

I've read through a dozen related issues and articles, but nothing is working for me

  • Install npm module from gitlab private repository
  • Install npm module from gitlab private repository
  • Use dependencies from a private GitLab with NPM
  • https://hackernoon.com/private-npm-packages-2e6579b37616
like image 242
islalobo Avatar asked Jan 28 '19 15:01

islalobo


People also ask

How do I use npm private packages?

With npm private packages, you can use the npm registry to host code that is only visible to you and chosen collaborators, allowing you to manage and use private code alongside public code in your projects. Private packages always have a scope, and scoped packages are private by default.

How install npm with all dependencies?

Install the dependencies to the local node_modules folder. In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package. By default, npm install will install all modules listed as dependencies in package. json .

How do I add a Git repo to a npm package?

To npm install a public project that is hosted on Github, and not the NPM registry, add the Github repo to package. json dependencies using the username/repo#branch-name format. Run npm install and npm will download the project and save it into your /node_modules/ folder.


1 Answers

I've got the same issue and I managed to fix it. The gitlab repository that I wanted to install didn't have a package.json file.

like image 75
erwamartin Avatar answered Oct 24 '22 21:10

erwamartin