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://git@my-domain.com: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
You should use Scopes if you want to install private npm packages.
You can define a scope in .npmrc file of your repository.
example .npmrc in your application repo:
@scopeName:registry=http://private-npm-registry/
always-auth=true
So npm can handle a dependency like: @scopeName/yourprivateModule@version
The token to access this repo should not be included in your Repository in should be configured in your home folders .npmrc . Npm will first look in ther current folder for a .npmrc and later in your home folder. The configured options will be merged.
But this approach is only good for you if you publish your package to a private npm registry. https://docs.gitlab.com/ee/user/project/packages/npm_registry.html#authenticating-with-an-oauth-token
So to summarize this:
add scoped dependency to your package.json
eg
npm i @scopeName/yourprivateModule@version
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.
On npm install, the error npm ERR! premature close
npm ERR! premature close
seems common if there's any problems with depency package.json's...
In my case, I had an illegal version number ("1" instead of "1.0.0"). This was not an issue on my local environment, but only when deploying to remote production. Fixing this cleared the error right away.
For reference this is my dependency line:
"myCustomRepo" : "git+https://MyGithubUsername:MyGithubPublicAccessToken@github.com/MyGithubUsername/myCustomRepo"
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.