10

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

1
  • 2
    Were you able to fix this issue ? Commented Jul 7, 2020 at 15:19

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Check dependency package.json

On npm install, the error npm ERR! premature close seems common if there's any problems with depency package.json's...

  • Does a package.json exist?
  • Is everything inside absolutely correct?
  • Everything ok with dependencies dependencies?

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:[email protected]/MyGithubUsername/myCustomRepo"

Comments

-1

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:

  • configure your scope in a .npmrc file of your repository
  • configure access token in .npmrc file of your environment user
  • add scoped dependency to your package.json

    e.g.

npm i @scopeName/yourprivateModule@version

9 Comments

Thanks, I'm not publishing the package to a private npm registry but rather attempting to instal from a private gitlab repository
Yes you have wrote that. I just wanted to point you to an easier solution. Maybe the error message is a little bit unclear. I can imagine that your dependency repo doesn't have a package.json.? I would check that at first.
The dependency repo does have a package.json - but it could be that it isn't recognized for some reason based on errors I see when trying to install with an access token
I'm not sure how to ensure the package.json file is visible if it's there but not recognized by npm
Also, it's cost money to publish private npm packages, whereas this ~should~ work according to the documentation
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.