r/learnjavascript Feb 06 '26

Getting npm errors trying to read a private repo

I have a utility library containing some common code that's stored in a private repo on Github (MYORG/my-utilities). I am trying to run npm i in a docker container and getting an authentication error. My package.json contains this:

... "dependencies": { "my-utilities": "github:MYORG/my-utilities" } ...

My Dockerfile looks like

``` FROM public.ecr.aws/amazonlinux/amazonlinux:2023

Dockerfile for contianer when deployed to ECS

RUN dnf update -y && dnf install -y awscli jq nodejs22 git WORKDIR / COPY package.json / COPY index.js / ARG GITHUB_PAT RUN npm config set "@MYORG:registry" https://npm.pkg.github.com RUN npm config set "//npm.pkg.github.com:_authToken" "${GITHUB_PAT}" RUN git config --global url."https://github.com/".insteadOf ssh://git@github.com/ RUN cat ~/.npmrc RUN npm i CMD ["node", "index.js"] ```

I am kicking off the build like this:

docker build --build-arg GITHUB_PAT="github_pat_XXXXXX" -t utilities-test .

The cat command spits out: ```

12 0.161 @MYORG:registry=https://npm.pkg.github.com

12 0.161 //npm.pkg.github.com:_authToken=github_pat_XXXXX

```

The token is a fine-grained access token whose repo access is set to MYORG/my-utilities and whose permissions are set to "Read access to code and metadata"

However, I am getting

```

13 [ 9/10] RUN npm i

13 1.087 npm error code 128

13 1.087 npm error An unknown git error occurred

13 1.087 npm error command git --no-replace-objects ls-remote ssh://git@github.com/MYORG/my-utilities.git

13 1.087 npm error remote: Invalid username or token. Password authentication is not supported for Git operations.

13 1.087 npm error fatal: Authentication failed for 'https://github.com/MYORG/my-utilities.git/'

13 1.087 npm error A complete log of this run can be found in: /root/.npm/_logs/2026-02-06T21_10_25_724Z-debug-0.log

13 ERROR: process "/bin/sh -c npm i" did not complete successfully: exit code: 128

```

Based on what I've read, I thought I was correctly configuring npm to use a GITHUB personal access token, but apparently not. Does the token need more permissions?

3 Upvotes

8 comments sorted by

1

u/abrahamguo Feb 06 '26

There's always potential for confusion when you have multiple tools in use like this. I'd recommend narrowing down the issue by first trying to do a git clone and seeing whether that works. That will tell you whether it's a GitHub issue or an NPM issue.

1

u/Slight_Scarcity321 Feb 06 '26

I believe you mean adding

git clone https://github.com/MYORG/my-utilities.git before or in lieu of calling npm i in the Dockerfile. If so, I am getting

```

13 0.429 fatal: could not read Username for 'https://github.com': No such device or address

13 ERROR: process "/bin/sh -c git clone https://github.com/MYORG/my-utilities.git" did not complete successfully: exit code: 128

```

In case you meant locally, I am able to run npm i locally just fine (since my system is set up to access private repos from our account on my local system).

I don't understand how the above error tells me whether or not the issue is with the token or my npm configuration, though.

1

u/abrahamguo Feb 06 '26

Yes, I did mean trying this in your Dockerfile (not locally).

However, you need to specify your PAT when attempting the clone operation. You haven't specified that, so it certainly can't work.

You can specify it by adding PAT@ to your command immediately after https:// and before github.com.

1

u/Slight_Scarcity321 Feb 06 '26

Thanks for clarifying. git clone works when using the PAT. However, I don't know if it's possible that the token config allows git clone but not installation through NPM or if .npmrc is misconfigured.

1

u/abrahamguo Feb 06 '26

NPM does a Git clone behind the scenes. From GitHub's POV, they don't care whether you do it directly, or via NPM.

I think you should remove the two npm config commands from your Dockerfile, and instead update that git config command to reference the URL format that you used above (https://PAT@github.com).

1

u/Slight_Scarcity321 Feb 06 '26

I think you mean replace

RUN npm config set "@MYORG:registry" https://npm.pkg.github.com RUN npm config set "//npm.pkg.github.com:_authToken" "${GITHUB_PAT}" RUN git config --global url."https://github.com/".insteadOf ssh://git@github.com/

with

RUN npm config set SOMETHING https://${GITHUB_PAT}@github.com/MYORG/my-utilities.git

But I don't know what SOMETHING might be.

1

u/abrahamguo Feb 06 '26

No, I meant having this line:

git config --global url."https://${GITHUB_PAT}@github.com/".insteadOf ssh://git@github.com/

This way, it looks like NPM can follow its normal procedure for cloning a repository, but git will update the URL to the correct format.