【问题标题】:Heroku Unable to Properly Use NPM_CONFIG variable at deployHeroku 在部署时无法正确使用 NPM_CONFIG 变量
【发布时间】:2020-08-03 18:51:51
【问题描述】:

我正在使用来自 GitHub 的私有包。尝试部署时,Heroku 会忽略我的 .npmrc 文件配置。

在本地,我的环境文件如下所示:

NPM_CONFIG_GITHUB_TOKEN=[token]

然后,我的.npmrc 文件如下所示:

[username]:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN

有了这个配置,我就可以在本地运行它了。在 Heroku 中,我收到以下错误:

-----> Node.js app detected
       
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       NPM_CONFIG_GITHUB_TOKEN=[token]
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       NODE_VERBOSE=false
       
-----> Installing binaries
       engines.node (package.json):  12.13.x
       engines.npm (package.json):   unspecified (use default)
       
       Resolving node version 12.13.x...
       Downloading and installing node 12.13.1
       Using default npm version: 6.12.1
       
-----> Restoring cache
       Cached directories were not restored due to a change in version of node, npm, yarn or stack
       Module installation may take longer for this build
       
-----> Installing dependencies
       Installing node modules
       npm ERR! code E401
       npm ERR! 401 Unauthorized - GET https://npm.pkg.github.com/download/[package]
       
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /tmp/npmcache.P5iPk/_logs/2020-08-03T18_44_16_744Z-debug.log
-----> Build failed

完整的日志说同样的事情。但是,如果我将.npmrc 更改为:

[username]:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}

...它在 Heroku 中运行良好,但在本地中断。

任何人都可以就我在这里做错了什么提供一些指导吗?我已经研究了几个小时没有成功。虽然显而易见的解决方案是不同的本地版本,但这是一个开源项目,我希望能够提供简单的安装说明。

【问题讨论】:

  • 我也有同样的问题,你是怎么解决的?

标签: node.js heroku heroku-nodejs


【解决方案1】:

当我部署到 Heroku 时,我通常会在 Heroku 上的应用设置中设置环境变量,我从来没有遇到过问题,您可以尝试一下

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 2020-09-21
    • 1970-01-01
    • 2020-06-14
    相关资源
    最近更新 更多