javascript 出现错误“Firebase函数部署:解析函数触发器时出错”[closed]

jogvjijk  于 2022-10-30  发布在  Java
关注(0)|答案(1)|浏览(191)

**已关闭。**此问题为not reproducible or was caused by typos。目前不接受答案。

这个问题是由一个打字错误或一个无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
1小时前关闭。
Improve this question
我有一个解析问题的函数.pubsub时,做一个Firebase部署,我不知道为什么,我检查堆栈溢出的一切,但似乎没有工作。
为什么会这样?我不知道我在这一点上做错了什么。
这是代码:

const functions = require("firebase-functions");
const axios = require("axios");
const admin = require("firebase-admin");
admin.initializeApp();
const database = admin.firestore();
const page = 1;
const fiat = "RON";
const tradeType = "BUY";
const asset = "USDT";
const payTypes = ["ING"];
let finalData = [];
let tempDataBeforeProccessing = [];

const baseObj = {
  page,
  rows: 20,
  publisherType: null,
  asset,
  tradeType,
  fiat,
  payTypes,
};

const stringData = JSON.stringify(baseObj);

const getTheData = async function() {
  tempDataBeforeProccessing=[];
  await axios.post("https://p2p.binance.com/bapi/c2c/v2/friendly/c2c/adv/search", baseObj, {
    hostname: "p2p.binance.com",
    port: 443,
    path: "/bapi/c2c/v2/friendly/c2c/adv/search",
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Content-Length": stringData.length,
    },
  }).then((res)=>{
    tempDataBeforeProccessing=res.data.data;
  });
};

const processData = function() {
  finalData=[];
  let obj = [];
  for (let i = 0; i < tempDataBeforeProccessing.length; i++) {
    let payTypesz = "";
    for (let y = 0; y <
    tempDataBeforeProccessing[i]["adv"]["tradeMethods"].length; y++) {
      payTypesz +=
      tempDataBeforeProccessing[i]["adv"]["tradeMethods"][y]["identifier"];
      if (y <
      tempDataBeforeProccessing[i]["adv"]["tradeMethods"].length - 1) {
        payTypesz += ", ";
      }
    }
    obj = {
      tradeType: tempDataBeforeProccessing[i]["adv"]["tradeType"],
      asset: tempDataBeforeProccessing[i]["adv"]["asset"],
      fiatUnit: tempDataBeforeProccessing[i]["adv"]["fiatUnit"],
      price: tempDataBeforeProccessing[i]["adv"]["price"],
      surplusAmount:
      tempDataBeforeProccessing[i]["adv"]["surplusAmount"],
      maxSingleTransAmount:
      tempDataBeforeProccessing[i]["adv"]["maxSingleTransAmount"],
      minSingleTransAmount:
      tempDataBeforeProccessing[i]["adv"]["minSingleTransAmount"],
      nickName:
      tempDataBeforeProccessing[i]["advertiser"]["nickName"],
      monthOrderCount:
      tempDataBeforeProccessing[i]["advertiser"]["monthOrderCount"],
      monthFinishRate:
      tempDataBeforeProccessing[i]["advertiser"]["monthFinishRate"],
      payTypes: payTypesz,
    };
    finalData.push(obj);
  }

  console.log(finalData);
};

const entireCall = async function() {
  await getTheData();
  processData();
};

exports.scheduledFunctionBRCSEBI = async functions.pubsub
      .schedule("* * * * *")
      .onRun(async (context) => {
        await database.collection("SebiBinanceSale").doc("BCR Bank").delete();
        await entireCall();
        for (let i = 0; i < finalData.length; i++) {
          database.collection("SebiBinanceSale").doc("BCR Bank")
              .collection("1").doc(i.toString())
              .set({
                "tradeType": finalData[i]["tradeType"],
                "asset": finalData[i]["asset"],
                "fiatUnit": finalData[i]["fiatUnit"],
                "price": finalData[i]["price"],
                "surplusAmount": finalData[i]["surplusAmount"],
                "maxSingleTransAmount": finalData[i]["maxSingleTransAmount"],
                "minSingleTransAmount": finalData[i]["minSingleTransAmount"],
                "nickName": finalData[i]["nickName"],
                "monthOrderCount": finalData[i]["monthOrderCount"],
                "monthFinishRate": finalData[i]["monthFinishRate"],
                "payTypes": finalData[i]["payTypes"],
              });
        }
        console.log("Succes Upload of the data ");
      });

错误在此行中:exports.scheduledFunctionBRCSEBI = async functions.pubsub,在这里你可以看到函数。pubsub,world函数是错误的。
这是错误:

functions: Finished running predeploy script.
⚠  functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory.
⚠  functions: Please note that there will be breaking changes when you upgrade.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled

Error: Error occurred while parsing your function triggers.

/Users/ivanoiualexandrupaul/StudioProjects/BeconCryptoProject/binance/functions/index.js:87
exports.scheduledFunctionBRCSEBI = async functions.pubs
                                         ^^^^^^^^^

SyntaxError: Unexpected identifier
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at loadModule (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/runtimes/node/triggerParser.js:10:16)
    at /usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/runtimes/node/triggerParser.js:34:21
    at Object.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/runtimes/node/triggerParser.js:72:3)

Having trouble? Try firebase [command] --help

这是eslintrc:

module.exports = {

  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    "eslint:recommended",
    "google",
  ],
  rules: {
    quotes: ["error", "double"],
  },
  parserOptions: {
    parser: "babel-eslint",
    ecmaVersion: 8,
    sourceType: "module",
  },
};

这是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": "16"
  },
  "main": "index.js",
  "dependencies": {
    "async": "^3.2.4",
    "cors": "^2.8.5",
    "firebase-admin": "^10.3.0",
    "firebase-functions": "^4.0.1",
    "request": "^2.88.2",
    "request-promise": "^4.2.6"
  },
  "devDependencies": {
    "eslint": "^8.9.0",
    "eslint-config-google": "^0.14.0",
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}
1tuwyuhd

1tuwyuhd1#

为了修复它,你必须删除functions.pubsub前面的async世界,它才能工作。我知道一个小错误,这也是一个愚蠢的错误,因为async不应该去那里。

exports.scheduledFunctionBRCSEBI = functions.pubsub
          .schedule("* * * * *")
          .onRun(async (context) => {
            await database.collection("SebiBinanceSale").doc("BCR Bank").delete();
            await entireCall();
            for (let i = 0; i < finalData.length; i++) {
              database.collection("SebiBinanceSale").doc("BCR Bank")
                  .collection("1").doc(i.toString())
                  .set({
                    "tradeType": finalData[i]["tradeType"],
                    "asset": finalData[i]["asset"],
                    "fiatUnit": finalData[i]["fiatUnit"],
                    "price": finalData[i]["price"],
                    "surplusAmount": finalData[i]["surplusAmount"],
                    "maxSingleTransAmount": finalData[i]["maxSingleTransAmount"],
                    "minSingleTransAmount": finalData[i]["minSingleTransAmount"],
                    "nickName": finalData[i]["nickName"],
                    "monthOrderCount": finalData[i]["monthOrderCount"],
                    "monthFinishRate": finalData[i]["monthFinishRate"],
                    "payTypes": finalData[i]["payTypes"],
                  });
            }
            console.log("Succes Upload of the data ");
          });

相关问题