我尝试部署firebase函数,但由于ESLint的某些问题,它一直在失败.我也试过谷歌搜索答案,但我看到的一切都是希腊语给我.
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// });
//import firebase functions modules
const functions = require("firebase-functions");
//import admin module
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
// Listens for new messages added to messages/:pushId
exports.pushNotification = functions.database.ref("/Message").onWrite( event => {
// Grab the current value of what was written to the Realtime Database.
var valueObject = event.data.val(); …
Run Code Online (Sandbox Code Playgroud) 我最近在尝试部署我的firebase函数时遇到此错误.但是,自上次成功部署以来,我没有更改任何依赖项...
? functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (57.25 KB) for uploading
? functions: functions folder uploaded successfully
i functions: updating Node.js 6 function firestoreEmail(us-central1)...
i functions: updating Node.js 6 function apiMain(us-central1)...
? functions[apiMain(us-central1)]: Successful update operation.
? functions[firestoreEmail(us-central1)]: Deployment error.
Build failed: exit status 1
npm ERR! Linux 4.4.0-133-generic
npm ERR! argv "/nodejs/bin/node" "/nodejs/bin/npm" "--global-style" "--production" "--fetch-retries=5" "--fetch-retry-factor=2" "--fetch-retry-mintimeout=1000" "install" "/workspace"
npm ERR! node v6.14.0
npm ERR! npm …
Run Code Online (Sandbox Code Playgroud) 当我运行firebase init
以启动一个新项目 时,当我转到 firebase 仪表板时,会自动创建 package.json 文件(如下所示),然后它会抛出此警告”
Run Code Online (Sandbox Code Playgroud)Starting NaN, NaN, we'll no longer support new deploys or updates of Node.js 8 functions. Starting NaN, NaN, we'll no longer support executions of existing Node.js 8 functions.
你如何初始化和指定版本?或者有什么解决方法?
{
"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": "8"
},
"dependencies": …
Run Code Online (Sandbox Code Playgroud) 我有一个名为的子模块shared
,它位于backend
文件夹(即云函数文件夹)旁边:
我已经添加了局部依赖shared
于backend/package.json
像这样:
"dependencies": {
...
"shared": "file:../shared"
}
Run Code Online (Sandbox Code Playgroud)
我跑了npm install
并确保它node_modules/shared
存在。虽然,当我运行以下代码时:
firebase deploy --only functions
Run Code Online (Sandbox Code Playgroud)
我收到以下错误(通过 firebase):
Error: Error parsing triggers: Cannot find module 'shared/common'
Try running "npm install" in your functions directory before deploying.
Run Code Online (Sandbox Code Playgroud)
此错误是由于此行:
import { currentWeek } from 'shared/common';
Run Code Online (Sandbox Code Playgroud)
如果我将目录更改为../../../shared/common
,firebase 将编译而不会出现任何错误。
export { currentWeek } from './current-week';
Run Code Online (Sandbox Code Playgroud)
{
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"module": "commonjs",
"declaration": true,
"strict": true,
"removeComments": true …
Run Code Online (Sandbox Code Playgroud) 当我尝试从项目中的functions目录启动外壳程序进行本地测试时,模拟器会启动,但无法加载我的函数。
当我运行“ npm run build”时,我没有收到任何错误。怎么了?
我尝试删除功能目录并使用firebase-tools cli再次创建它,但仍然出现相同的错误。我还导出了管理员凭据。
我正在使用从firebase-tools cli生成的index.ts文件中创建的默认方法。
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
export const helloWorld = functions.https.onRequest((request,
response) => {
response.send("Hello from Firebase!");
});
Run Code Online (Sandbox Code Playgroud)
我希望仿真器启动该函数的实例进行测试,但相反,我看到此错误:
? functions: Emulator started at http://localhost:5001
? TypeError: _onRequestWithOpts is not a function
at Object.httpsProvider._onRequestWithOpts (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:278:24)
at Object.httpsProvider.onRequest (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:283:34)
at Object.<anonymous> (/Volumes/G-DRIVE mobile USB-C/CLEAN UP/Documents/code_bank/typescript/theincrowdapp/functions/lib/index.js:9:38)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at …
Run Code Online (Sandbox Code Playgroud) 我正在尝试为Firebase Cloud Functions编写一个onCall函数,该函数在Firestore数据库上执行高级查询任务(即,根据AutoML自然lang检查文本查询以获取类别,等等),但是在尝试查询来自数据库的功能:
Error getting documents :: Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/srv/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
Run Code Online (Sandbox Code Playgroud)
功能:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
exports.query = functions.https.onCall((data, context) => {
const text = data.text;
var results = [];
const promise = db.collection('providers').get()
promise.then((snapshot) => {
console.log('marker');
snapshot.forEach((doc) => {
results.push({id: doc.id, data: doc.data()});
});
console.log('yessir');
return {results: results};
}).catch((err) => {
console.log('Error …
Run Code Online (Sandbox Code Playgroud) firebase google-oauth google-cloud-functions google-cloud-firestore firebase-cli
我一直在尝试新的firebase可调用云功能,firebase functions:shell
我继续得到以下错误
请求的内容类型不正确.
和
从功能收到的响应:400,{"error":{"status":"INVALID_ARGUMENT","message":"Bad Request"}}
这是我想在shell上调用此函数
myFunc.post(dataObject时)
我也尝试过这个
myFunc.post().表(dataObject时)
但后来我得到错误的编码(表单)错误.dataObject
是有效的JSON.
更新:
我想我需要firebase serve
用于本地仿真这些callable https
功能.数据需要像这样在post请求中传递(注意它在data
参数中的嵌套方式)
{
"data":{
"applicantId": "XycWNYxqGOhL94ocBl9eWQ6wxHn2",
"openingId": "-L8kYvb_jza8bPNVENRN"
}
}
Run Code Online (Sandbox Code Playgroud)
我无法想象的是如何通过REST客户端调用该函数时传递虚拟身份验证信息
每当我在我的mac上运行firebase服务器时,我收到404错误...这在以前从未发生过,我只是在开始发生前5分钟使用本地开发服务器.我删除了firebase.json文件并重新初始化它,重新安装了firebase工具,但每次都失败了.以下是在调试模式下运行命令的结果.
firebase serve --debug
[2018-09-11T16:12:25.873Z] ----------------------------------------------------------------------
[2018-09-11T16:12:25.876Z] Command: /usr/local/bin/node /usr/local/bin/firebase serve --debug
[2018-09-11T16:12:25.877Z] CLI Version: 4.2.1
[2018-09-11T16:12:25.877Z] Platform: darwin
[2018-09-11T16:12:25.877Z] Node Version: v6.11.3
[2018-09-11T16:12:25.878Z] Time: Tue Sep 11 2018 11:12:25 GMT-0500 (CDT)
[2018-09-11T16:12:25.878Z] ----------------------------------------------------------------------
[2018-09-11T16:12:25.890Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2018-09-11T16:12:25.890Z] > authorizing via signed-in user
[2018-09-11T16:12:25.893Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/skadaddle-10f24
[2018-09-11T16:12:26.210Z] <<< HTTP RESPONSE 200 server=nginx, date=Tue, 11 Sep 2018 16:12:26 GMT, content-type=application/json; charset=utf-8, content-length=114, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store
[2018-09-11T16:12:26.212Z] >>> HTTP REQUEST GET https://cloudresourcemanager.googleapis.com/v1/projects/skadaddle-10f24
[2018-09-11T16:12:26.385Z] …
Run Code Online (Sandbox Code Playgroud) Started firebase project emulators (which uses cloud functions and firestore) with below command
firebase emulators:start
Run Code Online (Sandbox Code Playgroud)
It runs successfully and gives me a path to connect to the functions and shows a local host url for firestore too.
Then, to execute my jest tests, ran the below command
firebase emulators:exec --only firestore jest
Run Code Online (Sandbox Code Playgroud)
As per the documentation, to connect to local firstore, we need to use exec. But its throwing below error.
i emulators: Starting emulators: firestore
? emulators: emulator hub …
Run Code Online (Sandbox Code Playgroud) 我正在将firebase login:ci
令牌用于 CI/CD。但是没有足够的关于令牌的文档。
它是否有权访问我的帐户有权访问的所有 firebase 项目或仅访问当前活动的项目?
我在哪里可以看到所有代币及其活动的列表?
我要寻求的解决方案是创建一个一次性电子邮件并将其添加到我要部署的项目中。这个可以吗?
firebase-cli ×10
firebase ×8
node.js ×2
typescript ×2
eslint ×1
google-oauth ×1
package.json ×1