Apify Discord Mirror

Updated 5 months ago

Problem building with private packages

At a glance

The community member is experiencing an issue with accessing private packages on an Actor JS/Typescript- Engine Node 18 project. They have followed the steps of creating a secret with the NPM_GITHUB_TOKEN, adding it to the Dockerfile, and creating the .npmrc file, but they are still getting a 401 Unauthorized error when trying to download the packages.

In the comments, another community member suggests adding the .npmrc file to the Dockerfile before the npm install step, and providing the necessary authentication details in the .npmrc file. This seems to have resolved the issue for the original poster.

The community member also mentions that it is possible to tell Apify to apply the environment variable during the build process from the GUI, but they are using the Apify CLI and automating the process via GitHub Actions, which does not seem to work with this approach. A community member suggests that this might be possible via the Apify API, but they are unsure about the CLI.

There is no explicitly marked answer, but the community members have provided a solution to the original issue.

Useful resources
Hi everyone, nice to be here 😁

I am writing to you about a problem with private packages on an Actor JS/Typescript- Engine Node 18.

I followed these steps:
  • I created a secret with the NPM_GITHUB_TOKEN
  • checked the option from GUI "Apply environment variables also to the build process"
  • I added these lines to my Dockerfile
ARG NPM_GITHUB_TOKEN ENV NPM_GITHUB_TOKEN=$NPM_GITHUB_TOKEN
and tried printing the value of the NPM_GITHUB_TOKEN in the build (it works)
  • I correctly created the .npmrc file that uses the NPM_GITHUB_TOKEN
I always get this error:

npm ERR!
2023-12-02T07:09:42.306Z 401 Unauthorized - GET https://npm.pkg.github.com/download/.........

Locally everything works correctly.
Has anyone had and solved a similar problem? I searched in old posts but couldn't find anything.
Thanks
L
m
A
8 comments
We did with adding this to Dockerfile before npm install

Plain Text
# <--- Copy the .npmrc file. --->
# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY code/package*.json code/.npmrc ./


Then having .npmrc file on top level with something like this

Plain Text
@apify-projects:registry=https://npm.pkg.github.com/apify-projects
//npm.pkg.github.com/:_authToken=ghp_vz34528RfdgfdgONJlfsdfFxVjsfdQRCT
ahh thanks , now it works, I was missing that little detail about not copying the .npmrc file, that had to be done in two different points
I also find out that it seems that it's possible to tell apify to apply env variable also during build time only from the GUI like this, there's no other way? I'm creating actor via apify-cli using apify-cli push and planning to automating it via github actions and obviously this will not work with this
This should be possible via API but not sure if CLI, good point, I will pass it to the team
Hi , by any change any update from the team on this?
just advanced to level 1! Thanks for your contributions! πŸŽ‰
Nope, I would not waitt for this for now
Add a reply
Sign up and join the conversation on Discord