使用GitHub Actions从私有GitHub存储库安装npm模块

问题描述 投票:2回答:2

我正在尝试使用GitHub Actions为Node.js项目运行构建。作为npm install的一部分,我需要直接从私有GitHub存储库中安装npm模块(而不是从GPR!)。

package.json中,我有:

"dependencies": {
  ...
  "my-module": "github:<org>/<my-module>#master",
  ...
},

但是,当运行npm install时,我得到:

npm ERR! [email protected]:权限被拒绝(公钥)。npm ERR!致命的:无法从远程存储库读取。

存储库是我自己组织的一部分,并且在本地(即从我的计算机上)可以运行。我该如何运行?

我已经尝试设置NODE_AUTH_TOKEN环境变量,但是没有什么区别。尽管您经常发现此建议,但它似乎只能解决GPR。我要避免的是必须将令牌硬编码到package.json文件中。有什么想法吗?

node.js github npm github-actions
2个回答
0
投票

从错误以及包含依赖项的方式(在package.json中,看来您没有通过身份验证凭据(令牌,ssh。)>

有关Git URLs as Dependencies的详细信息,请参阅此文档,>

可以通过https和oauth或ssh完成。

https和oauth

:具有“回购”范围的create an access token,然后具有use this syntax:]]
"package-name": "git+https://<github_token>:[email protected]/<user>/<repo>.git"

ssh

:设置ssh,然后使用以下语法:
"package-name": "git+ssh://[email protected]:<user>/<repo>.git"
(note the use of colon instead of slash before user)
 

您应该编辑您的.npmrc文件。您也可以使用npm config

npm config set @myco:registry http://reg.example.com

请参阅以下主题以获取更多信息:Is there any way to configure multiple registries in a single npmrc file


-1
投票

您应该编辑您的.npmrc文件。您也可以使用npm config

npm config set @myco:registry http://reg.example.com

© www.soinside.com 2019 - 2024. All rights reserved.