NPM - 无法替换配置中的 env:${NPM_TOKEN} [英] NPM - Failed to replace env in config: ${NPM_TOKEN}

查看:169
本文介绍了NPM - 无法替换配置中的 env:${NPM_TOKEN}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个 React 应用程序,但是当我执行命令 npm -i 时,它给了我以下错误:

I am trying to build a react app, but when I execute the command npm -i it gives me the following error:

Error: Failed to replace env in config: ${NPM_TOKEN}
    at /usr/local/lib/node_modules/npm/lib/config/core.js:415:13
    at String.replace (<anonymous>)
    at envReplace (/usr/local/lib/node_modules/npm/lib/config/core.js:411:12)
    at parseField (/usr/local/lib/node_modules/npm/lib/config/core.js:389:7)
    at /usr/local/lib/node_modules/npm/lib/config/core.js:330:24
    at Array.forEach (<anonymous>)
    at Conf.add (/usr/local/lib/node_modules/npm/lib/config/core.js:328:23)
    at ConfigChain.addString (/usr/local/lib/node_modules/npm/node_modules/config-chain/index.js:244:8)
    at Conf.<anonymous> (/usr/local/lib/node_modules/npm/lib/config/core.js:316:10)
    at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
/usr/local/lib/node_modules/npm/lib/npm.js:61
      throw new Error('npm.load() required')
      ^

Error: npm.load() required
    at Object.get (/usr/local/lib/node_modules/npm/lib/npm.js:61:13)
    at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:205:18)
    at process.emit (events.js:182:13)
    at process._fatalException (internal/bootstrap/node.js:448:27)

我使用的是 MacOS High Sierra.我尝试使用以下命令将 NPM_TOKEN 设置为环境变量:

I am using MacOS High Sierra. I tried to set the NPM_TOKEN as an environment variable with following command:

set -x NPM_TOKEN = xyz

但它不起作用.有什么问题?

but it doesn't work. What is the problem?

推荐答案

第一个可能的解决方案:

简单解决方案:rm -f ./.npmrc(删除.npmrc文件)

First Possible Solution:

Simple Solution: rm -f ./.npmrc (Deleting a .npmrc file)

但是,如果您不想删除该文件,则只需删除 .npmrc 文件中的这行代码即可.

However if you don't want to delete the file, you can simply remove this line of code in the .npmrc file.

代码行://registry.npmjs.org/:_authToken=${NPM_TOKEN}(删除此代码)

Line of Code: //registry.npmjs.org/:_authToken=${NPM_TOKEN} (Remove this code)

最坏情况:

  • nano ~/.bash_aliasesnano ~/.bash_profile
  • 添加export NPM_TOKEN="XXXXX-XXXXX-XXXXX-XXXXX"
  • CTRL + X 退出
  • Y 保存

这篇关于NPM - 无法替换配置中的 env:${NPM_TOKEN}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆