Getting 401 error when running npm install with private repository dependency

I’m having trouble installing a package from a private GitLab repository, as I keep receiving authorization errors.

This is how my package.json file looks for the dependency:

"logger-utils": "https://gitlab.company.com/team/utilities/repository/archive.tar.gz?ref=1.2.0"

Upon executing the install command, the following error message occurs:

john@Johns-MacBook ~/projects/webapp (feature/updates) $ npm install
npm ERR! code E401
npm ERR! 404 401 Unauthorized: logger-utils@https://gitlab.company.com/team/utilities/repository/archive.tar.gz?ref=1.2.0

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/john/.npm/_logs/2018-02-16T09_15_22_445Z-debug.log

I’m uncertain if the problem lies within GitLab configuration or my NPM setup. I can access the repository through the web interface without issues.

My current setup includes:

  • Node v8.9.4
  • NPM v5.6.0

Has anyone faced a similar issue? What’s the right approach to authenticate with private repositories?

i had the same issue before. try adding ur GitLab token to the URL like this: https://oauth2:[TOKEN]@gitlab.company.com/team/utilities/repository/archive.tar.gz?ref=1.2.0. just replace [TOKEN] with ur access token from GitLab. it worked for me!

Check if your GitLab token has expired or lacks sufficient permissions. I encountered this issue last month, and it turned out my token had been revoked during a security audit. Visit your GitLab profile settings to confirm your access tokens are active and have at least the read_repository scope. Additionally, some corporate GitLab configurations require deploy tokens rather than personal access tokens for API requests. If you have two-factor authentication enabled, ensure that you are generating the token correctly since regular passwords are not applicable for API access.

The 401 error indicates that npm is unable to authenticate with your private GitLab repository. Instead of linking directly to the archive, consider configuring npm to utilize GitLab’s package registry. Create a .npmrc file in your project directory and include your GitLab token there. Then, modify your package.json to adopt the npm registry format. This method will help secure your token, as it won’t be visible in the URLs. Ensure that your access token possesses the necessary scopes for the repository.

Been dealing with these auth headaches for years too. Manual token management gets messy fast, even though it works.

I automated this whole thing with Latenode. It monitors package dependencies, handles GitLab auth automatically, and updates expired tokens without me touching anything.

Best part? It pulls from multiple private repos across different platforms without hardcoded tokens. Connect GitLab once and it handles all the auth stuff.

Using it for our entire CI/CD pipeline now. Way better than scattered npmrc files and tokens someone always forgets to update.

use git+https syntax in your package.json, not direct archive links. try "git+https://gitlab-ci-token:[TOKEN]@gitlab.company.com/team/utilities.git#v1.2.0". archive urls don’t play nice with npm auth.

Your dependency URL is breaking authentication. GitLab’s direct archive links don’t play nice with npm auth. I hit this same issue migrating our old packages - switching to SSH fixed it instantly. Change your package.json to “logger-utils”: “git+ssh://[email protected]/team/utilities.git#1.2.0”. Just make sure your SSH key’s in GitLab and ssh-agent is running. Skips the token mess completely and uses your SSH setup instead. Way more reliable.