Scenario:
User experience ‘500 Internal Server Error’s when pulling remotely hosted images through Artifactory using a virtual repository.
A user is trying to install npm packages for the node project by running the command
npm i --loglevel verbose
errors like below are observed-
npm verb stack Error: 500 Internal Server Error – GET https://<ARTIFACTORY_URL>:<PORT>/artifactory/api/npm/npm/xyz/-/xyz-2.1.4.tgz
Solution:
I observed that sometimes users not being able to authenticate correctly to the Artifactory repository is the cause of this issue.
npm gets its config from .npmrc file. This file could be from these 4 places-
per-project config file (/path/to/my/project/.npmrc)
per-user config file (~/.npmrc)
global config file ($PREFIX/etc/npmrc)
npm builtin config file (/path/to/npm/npmrc)
Create a .npmrc file in per-project config file (/path/to/my/project/.npmrc)
Generate an Identity Token by navigating to Artifactory → Profile → Edit Profile → Generate an Identity Token.
Setup following in your .npmrc file (replacing the highlighted strings):
registry=https://<ARTIFACTORY_URL>:<PORT>/artifactory/api/npm/npm/ //<ARTIFACTORY_URL>:<PORT>/artifactory/api/npm/npm/:always-auth=true //<ARTIFACTORY_URL>:<PORT>/artifactory/api/npm/npm/:_authToken=RELACE_IDENTITY_TOKEN_HERE //<ARTIFACTORY_URL>:<PORT>/artifactory/api/npm/npm/:username=abc.xyz@yourmail.com //<ARTIFACTORY_URL>:<PORT>/artifactory/api/npm/npm/:email=abc.xyz@yourmail.com