site name:
admiring-sammet-ff69ee
Hello, I am looking to pull a private NPM package from my internally hosted Artifactory. I have been through this thread extensively
[Support Guide] Using private NPM modules on Netlify
What I have tried:
Setting a .npmrc in a .netlify folder, and modifying the .toml file to read from that.
Using the suggested preinstall script
netlify-preinstall.js
and attaching that script to the preinstall hook.
Tried replacing .npmrc with .yarnrc
In these solutions, I have printed out the files/folders in my directory in the script to confirm that .npmrc is not created initially, and printing out files/folder and the contents of .npmrc after.
The .npmrc is confirmed to be created with the correct internal contents, but I still get a 401 error upon trying to download the package.
Error:
Request failed "401 Unauthorized"".
11:58:59 AM: info If you think this is a bug, please open a bug report with the information provided in “/opt/build/repo/yarn-error.log”.
The only solution that has worked is to put a .npmrc at the root of my repo, however this is non-ideal as it requires engineers to set the envvar in their zsh/bash or export those variables.
Let me know if there is something I am doing wrong.
Thank you

kotybond:
Setting a .npmrc in a .netlify folder, and modifying the .toml file to read from that.
Hey
@kotybond
, could you explain how exactly you did this? From my understanding, this file should exist in your base path. Did you change the base path in your TOML file?
Yeah, I copied my
.npmrc
file into
.netlify
, fielding a structure of,
.netlify/.npmrc
.
My TOML file looks like:
[build]
NPM_CONFIG_USERCONFIG = "./netlify/.npmrc"
Wanted to say that @mpan-wework’s suggestion worked for me, and it felt like the least amount of compromise. The tricky bit is that the developers on my team need to use both private npm packages and packages published to a self-hosted GitLab registry, so there are multiple config steps required. I was able to create an .npmrc file in an arbitrary folder within my project(s), which is setup to use environment variables that I’ve set at a team level. I then added a line to netlify.toml to set the…