Skip to content

Private registry support does not work with npm version 7 #265

Closed
@Avaq

Description

@Avaq

I'm running into the issue described here: npm/cli#2508. This issue was closed by mistake (npm/cli#2508 (comment)), but it seems to be implied that it won't be fixed, and that something needs to change on setup-node's end to get things working again.

From my basic understanding, it's related to the way that setup-node configures the multiple registries:

const authString: string =
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
const registryString: string = scope
? `${scope}:registry=${registryUrl}`
: `registry=${registryUrl}`;
const alwaysAuthString: string = `always-auth=${alwaysAuth}`;
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);

To Reproduce

  1. Make sure your package-lock.json contains a private package that can only be accessed with your NPM_TOKEN. It's important to have a package-lock.json file as well as your regular package.json, because the issue only occurs when there is also a package lock, as hinted at by this comment: [BUG] NPM v7 private registry authentication 401 (v6 works) npm/cli#2508 (comment)
  2. Use a workflow like:
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v2
      with:
        node-version: '16.x' # Node version is important; It ensures that npm v7 is installed
        registry-url: 'https://registry.npmjs.org'
    - run: npm install --ignore-scripts
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions