簡體   English   中英

在 Google Cloud Functions 中安裝私有 GitHub npm package 不起作用

[英]Installing private GitHub npm package in Google Cloud Functions does not work

我正在嘗試將微服務部署到 GCF,它依賴於私有 GitHub 托管的 package。 為了訪問 package,我向 function 添加了一個 .npmrc 文件,如此處所述,該文件如下所示

registry=https://npm.pkg.github.com/OWNER
//npm.pkg.github.com/:_authToken=PERSONAL-ACCESS-TOKEN

還嘗試在雲 Function 中使用 NPM_TOKEN 環境變量

NPM_TOKEN=PERSONAL-ACCESS-TOKEN

兩者都會導致以下錯誤:

OperationError: code=3, message=Build failed: { error: { canonicalCode: "INVALID_ARGUMENT" }}

npm ERR:404 未找到:@packagescope/packagename

在本地安裝工作正常,在 Zeit Now 上部署也是如此。

我剛剛遇到了這個問題,所以我分享了適用於 node v8 和 v10 Cloud Functions 的修復程序。

使用.npmrc從私有 Github 包注冊表安裝包需要以下內容:

  1. .npmrc需要位於與package.json文件相同級別的功能文件夾中
  2. A registry entry for the your account/org scope is required, including the url like so, assuming Anchorman uses Github: @ronburgundy:registry=https://npm.pkg.github.com/ronburgundy
  3. 身份驗證需要 Github 個人訪問令牌,如下//npm.pkg.github.com/:_authToken=ronburgundypersonalaccesstoken
  4. 假設您遵循最佳實踐並且不使用機密提交.npmrc ,您需要確保在通過 firebase cli 部署之前將文件轉換為包含個人訪問令牌,因為沒有其他方法可以在運行時注入值。

因此,如果原始示例如下所示,它將起作用:

@OWNER:registry=https://npm.pkg.github.com/OWNER
//npm.pkg.github.com/:_authToken=PERSONAL-ACCESS-TOKEN

While Github's docs seem to suggest that you should redirect ALL scoped and unscoped package installs to their registry it appears that Google Cloud Functions does not allow us to redirect all package installs to a private registry, only those that we configure based on scope.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM