![](/img/trans.png)
[英]How To Setup Private NPM Module With Firebase Cloud Functions .npmrc?
[英]Installing private GitHub npm package in Firebase Cloud Functions
我是 Firebase Cloud Functions 的新手,一直在努力添加私有 npm 包以使我的函数正常工作。 我知道 Firebase 除非另有说明,否则会将它们全部视为公开的,并将使用 npm / yarn 安装我在 package.json 中的内容。
我告诉 Firebase 它是 Github 上的私有存储库的唯一方法是添加一个
.npmrc(包含)——我使用的密钥是来自 Github-Developers 的个人访问令牌,它具有所有需要的权限
//npm.pkg.github.com/:_authToken=<access token>
# @calugarul:registry=git+https://npm.pkg.github.com/calugarul
@calugarul:registry=git+https://<access token>@github.com/kroitor/ccxt.pro.git
在我的 index.js 文件中,我调用了私有存储库 (ccxt.pro),但它不会安装在 Firebase Cloud Functions 服务器上。
索引.js
const functions = require("firebase-functions");
var num = 1;
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
var moment = require('moment');
const ccxtpro = require ('ccxt.pro');
const coinbaseEx = new ccxtpro.coinbasepro({'enableRateLimit': true});
package.json(含)
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "14"
},
"main": "index.js",
"dependencies": {
"@calugarul/ccxt.pro": "git+https://github.com/kroitor/ccxt.pro.git",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.16.0",
"moment": "^2.29.1"
},
"devDependencies": {
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
常见错误:
E getTickersAndSendRequestToStart: {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"Build failed: npm ERR! Error while executing:\nnpm ERR! /usr/bin/git ls-remote -h -t https://github.com/kroitor/ccxt.pro.git\nnpm ERR! \nnpm ERR! remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.\nnpm ERR! remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.\nnpm ERR! fatal: Authentication failed for 'https://github.com/kroitor/ccxt.pro.git/'\nnpm ERR! \nnpm ERR! exited with error code: 128\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR! /www-data-home/.npm/_logs/2021-10-31T02_03_39_782Z-debug.log; Error ID: beaf8772"},"authenticationInfo":{"principalEmail":"my email"},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","resourceName":"projects/smart-trader-cd29f/locations/us-central1/functions/getTickersAndSendRequestToStart"}
macbookpro:functions cleo$
不知道怎么办,找了好几天了,没有结果。 请帮我想办法在部署功能时告诉 Firebase 安装私有存储库!
如果您使用 yarn (yarn.lock) 并且没有package-lock.json
,它会中断,因为 firebase CLI 在预部署中使用npm install
。 删除yarn.lock
并使用 npm 安装。
在寻找答案后,这是最简单的解决方案:
完全忽略了 .npmrc 文件并在依赖项下的 package.json 中添加了个人访问令牌,如下所示:<GITHUB_PERSONAL_ACCESS_TOKEN>@github.com
"dependencies": {
"@calugarul/ccxt.pro": "git+https://<GITHUB_PERSONAL_ACCESS_TOKEN>@github.com/kroitor/ccxt.pro.git",
"dotenv": "^10.0.0",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.16.0",
"moment": "^2.29.1"
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.