6

We have our own npm package and a project that uses it, I want to publish it to a tfs feed - repository and install it from there instead of from a physical file.

I published the package to the feed from my development machine,
and I changed the reference within the project that consumes it.

The whole process works fine from my machine, but when I try to consume the package on a build process in the tfs - it fails with the error :

Unable to authenticate, your authentication token seems to be invalid.

I've created .npmrc file at the project level with the registry address, and another file with credentials on the user directory, and I did the same on the TFS machine.

What can cause the npm install (from my feed) to not work on the tfs machine?

EDIT:
When I add prefix @my to the registry at the user-level .npmrc file - like this:

@my:registry=https://my-feed-address

The error changes to: "No valid versions available for my-package"

banana
  • 1,186
  • 4
  • 14
  • 26
  • The build agent run with user, give to this user permissions in the feed. – Shayki Abramczyk Jun 30 '19 at 13:39
  • @ShaykiAbramczyk, Do you mean Feed settings->Permissions ? If so, this user has owner permission. – banana Jul 01 '19 at 04:09
  • Can you share your build pipeline? – Shayki Abramczyk Jul 01 '19 at 05:57
  • @ShaykiAbramczyk, I do not think that's the point, Because even when I run the npm install command in the tfs server - in the project folder within the relevant 's' folder - I get the same behavior. + I edited my question. – banana Jul 02 '19 at 05:03
  • Which version of TFS is it? Are you using the npm install task? it has and authentication section that you can point to your .npmrc file. There is also a npm authenticate task you might want to run first. – Etienne Jul 04 '19 at 15:45
  • @Etienne, It was the 2017 version, and we upgraded it to the 2019 version to solve this problem but it did not help. I tried both the `'Registries in my .npmrc'` option and the `'Registry I select here'` option, with\without selection of a `Service connection` which I created that connects to my feed. But, as I wrote in the previous comment, why it would work if running this command **inside the tfs server** in command line - it does not work? (I do not know why) I get the same error. – banana Jul 08 '19 at 04:18
  • why do you think running it inside tfs server should skip auth? – 4c74356b41 Jul 08 '19 at 11:52
  • Try adding a variable system.debug with a value of true you’ll get more information in the failure. That might help pinpoint the problem – Etienne Jul 08 '19 at 12:56
  • @4c74356b41, When I run it inside the server - it should use the configuration an auth token listed in the npmrc file on the server, and it should succeed as it does from my machine, but it fails... – banana Jul 09 '19 at 06:18
  • @Etienne, Is system.debug a variable of the process in tfs? What I need is details from the **npm**. – banana Jul 09 '19 at 06:18
  • why do you think it should do that? also, can you verify the token is working? did you hardcode it? – 4c74356b41 Jul 09 '19 at 06:20
  • @4c74356b41, The process runs in this machine. If not from this file - where should it take the settings? How can I verify the token is working? And what do you mean by _did you hardcode it_? – banana Jul 09 '19 at 06:29
  • @banana by adding system.debug value of true, you'll get more info in the task log as to why npm authenticate doesn't work. – Etienne Jul 10 '19 at 12:10
  • @Etienne, But it will not give me more details than running the `npm install` command inside the tfs server in Command Line, is not it? – banana Jul 10 '19 at 12:18
  • It might give you the variables it uses and sometimes other errors – Etienne Jul 11 '19 at 12:08

2 Answers2

8
  1. Install this in machine: npm install -g vsts-npm-auth
  2. Run this (in the directory where npmrc file is): vsts-npm-auth -config .npmrc
technogeek1995
  • 3,185
  • 2
  • 31
  • 52
Leo BL
  • 316
  • 1
  • 9
  • i had the same problem but this solved in my case. in my build pipeline everytime before the restore i execute this vsts-npm-auth -config .npmrc. it works directly in build machine (without build process)? have you tried? – Leo BL Jul 10 '19 at 13:32
4

Create a file .npmrc in your project folder and add the following

registry=Your URL
always-auth=true

In the command prompt run both of these commands

npm install -g vsts-npm-auth --registry https://registry.npmjs.com --always-auth false

vsts-npm-auth -config .npmrc

Peter Morris
  • 20,174
  • 9
  • 81
  • 146
  • 3
    That's only works on Windows according to DevOps' documentation. – Ivan P Jan 29 '20 at 01:01
  • Does NOT work for ubuntu: `cannot execute binary file: Exec format error`... possibly this is only for Windows OS – ntg May 14 '21 at 05:13
  • For Windows this did it for me.... You have to enable the script polycies (e.g. `Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted` Yes ) – ntg Nov 25 '21 at 01:16