KEMBAR78
How to configure npm token via npm_config_* env var? · Issue #15565 · npm/npm · GitHub
Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

How to configure npm token via npm_config_* env var? #15565

@mk-pmb

Description

@mk-pmb

I'm opening this issue because:

  • npm is crashing.
  • npm is producing an incorrect install.
  • npm is doing something I don't understand.
  • Other (see below for feature requests):

What's going wrong?

npm seems to ignore my npm_config_//registry.npmjs.org/:_authToken environment variable.

I'm trying to restrict the environments where my npm login token is stored. I tried using an environment variable in my .npmrc as described in #8356 but adding that config line makes npm (e.g. npm --help) crash with Error: Failed to replace env in config: ${NPM_TOKEN} in all shells where the var isn't set.
Luckily, "npm is extremely configurable", so I tried the "environment variables" approach. Using the export command as suggested in the docs didn't work because:

bash: export: `npm_config_//registry.npmjs.org/:_authToken=00000000-0000-0000-0000-000000000000': not a valid identifier

… so instead I used env to spawn a new bash that would inherit my variable. Inside it, I used node.js to verify it is set correctly, then tried to publish:

$ env 'npm_config_//registry.npmjs.org/:_authToken=00000000-0000-0000-0000-000000000000' bash
$ # we're now in the inner shell
$ nodejs -p process.env | grep Token
  'npm_config_//registry.npmjs.org/:_authToken': '00000000-0000-0000-0000-000000000000',
$ npm pub .
npm ERR! Linux 3.13.0-108-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "pub" "."
npm ERR! node v6.9.4
npm ERR! npm  v3.10.10
npm ERR! code ENEEDAUTH
…

(Of course I used a token that worked in my .npmrc just seconds ago, so that should not be the problem.)

How can the CLI team reproduce the problem?

With the commands above, hopefully.

supporting information:

  • npm -v prints: 3.10.10
  • node -v prints: v6.9.4
  • npm config get registry prints: http://registry.npmjs.org/
  • Windows, OS X/macOS, or Linux?: Linux (Ubuntu 14.04.5 LTS trusty)
  • Network issues:
    • Geographic location where npm was run:
    • I use a proxy to connect to the npm registry.
    • I use a proxy to connect to the web.
    • I use a proxy when downloading Git repos.
    • I access the npm registry via a VPN
    • I don't use a proxy, but have limited or unreliable internet access.
  • Container:
    • I develop using Vagrant on Windows.
    • I develop using Vagrant on OS X or Linux.
    • I develop / deploy using Docker.
    • I deploy to a PaaS (Triton, Heroku).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions