Failed to replace env in config using Bash & NPM

I am trying to use a private NPM module in my application and must install the appropriate NPM access tokens so that third-party tools (Heroku and CI) can access and install the module.

I have the following set of lines in mine ~/.bash_profile:

export NPM_TOKEN="XXXXX-XXXXX-XXXXX-XXXXX"

and then in /path/to/app/.npmrcI have

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

However, whenever I open my terminal, I get the following error on startup:

Error: Failed to replace env in config: ${NPM_TOKEN}
    at /Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/lib/config/core.js:429:13
    at String.replace (native)
    at envReplace (/Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/lib/config/core.js:424:12)
    at parseField (/Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/lib/config/core.js:400:7)
    at /Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/lib/config/core.js:338:17
    at Array.forEach (native)
    at Conf.add (/Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/lib/config/core.js:337:23)
    at ConfigChain.addString (/Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/node_modules/config-chain/index.js:244:8)
    at Conf.<anonymous> (/Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/lib/config/core.js:325:10)
    at /Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:76:16
/Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/lib/npm.js:29
throw new Error('npm.load() required')
^

Error: npm.load() required
at Object.npm.config.get (/Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/lib/npm.js:29:11)
at exit (/Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/lib/utils/error-handler.js:58:40)
at process.errorHandler (/Users/marcthomas/.nvm/versions/node/v4.2.1/lib/node_modules/npm/lib/utils/error-handler.js:385:3)
at emitOne (events.js:77:13)
at process.emit (events.js:169:7)
at process._fatalException (node.js:221:26)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v4.2.1 --silent` to unset it.

However, the launch echo $NPM_TOKENreturns the correct token, so the variable definitely exists.

If I run source ~/.bash_profile, the error will disappear and I can install it as usual.

Any help is appreciated as I try to get my head down with this problem!

+11
4

export NPM_TOKEN="XXXXX-XXXXX-XXXXX-XXXXX" nvm .bash_profile

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
export NPM_TOKEN="XXXXX-XXXXX-XXXXX-XXXXX"

export NPM_TOKEN="XXXXX-XXXXX-XXXXX-XXXXX"
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
+23

rm -f ./.npmrc. .

+1

CI:

npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
npm publish

.npmrc:

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

GitHub: https://github.com/Jezorko/lambda-simulator/blob/master/.travis.yml

NPM.

"" -

, .npmrc.

, .npmrc VCS, . , .

, .npmrc . , , :

//registry.npmjs.org/:_authToken=${NPM_TOKEN:-undefined}

+1

"./.npmrc"

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

-1

Source: https://habr.com/ru/post/1629385/


All Articles