Hello! I am currently creating a CICD pipeline for our platform and am struggling with the automated builds for our front end.
It is a simple npm-based setup. We have a client library for our backend, which is privately stored in our GitHub organization. I modified our .npmrc file in our frontend to look as:
@<our organization>:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
I then created an environment variable via Terraform for the static site:
env {
key = "GITHUB_TOKEN"
value = "var.github_token"
scope = "BUILD_TIME"
type = "SECRET"
}
Now, when I trigger a deployment, I get the error:
npm ERR! code E401
npm ERR! 401 Unauthorized - GET <redacted> - authentication token not provided
Everything worked fine when I tested this locally with npm ci
after setting the environment variable.
Earlier in the build logs, it even states that it uses the GITHUB_TOKEN environment variable, I can only imagine that the node.js buildpack does not use it.
Any hint would be appreciated!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there!
I faced the exact same problem as you did. You were on the right track when you said that the build process ignored the .npmrc file. As such, I defined it inside the package.json file instead and it worked, something like this: “publishConfig”: { “@YOUR_USERNAME:registry”: “https://npm.pkg.github.com/”, “//npm.pkg.github.com/:_authToken”: “${YOUR_GITHUB_TOKEN}” },
Take note that I used an environment variable for YOUR_GITHUB_TOKEN, so do remember to define it as an environment variable inside your app platform.
Kind regards, Larry Thng
Hey!
It sounds like that you might have a
yarn.lock
file in your repository.If a
yarn.lock
file exists, App Platform will use Yarn. Otherwise, if apackage-lock.json
file exists, it will use NPM. It seems like Yarn doesn’t read.npmrc
files, so that’s why it’s failing trying to pull your private package.Can you confirm if this is the case?
Best,
Bobby
Okay Update: hardcoding the Secret into .npmrc doesn’t help, so apparently the install just ignores it. Anyone has an idea on how to mitigate this?