问题描述
我正在尝试在应用程序中使用私有NPM模块,并且需要设置适当的NPM访问令牌,以便第三方工具(Heroku和CI)可以访问并安装该模块.
I'm trying to use a private NPM module in my application, and need to set appropriate NPM access tokens so that third-party tools (Heroku and CI) can access, and install the module.
我在~/.bash_profile
中设置了以下行:
export NPM_TOKEN="XXXXX-XXXXX-XXXXX-XXXXX"
,然后在/path/to/app/.npmrc
我有
//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.
但是,运行echo $NPM_TOKEN
会返回正确的令牌,因此该变量肯定存在.
However, running echo $NPM_TOKEN
returns the correct token, so the variable definitely exists.
如果运行source ~/.bash_profile
,该错误消失,并且可以正常安装.
If I run source ~/.bash_profile
the error disappears, and I can install as normal.
在解决这个问题时,我正在用头撞墙,任何帮助都感激不尽!
Any help appreciated as I'm bashing my head against a wall at this problem!
推荐答案
对我来说,解决方法是将export NPM_TOKEN="XXXXX-XXXXX-XXXXX-XXXXX"
移到.bash_profile
The fix for me was moving export NPM_TOKEN="XXXXX-XXXXX-XXXXX-XXXXX"
before my nvm stuff in .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
这篇关于无法使用Bash& amp;在配置中替换env; NPM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!