firebase函数发送错误请求

sdnqo3pr  于 2022-12-19  发布在  其他
关注(0)|答案(1)|浏览(143)

我尝试从外部API获取json数据并将其保存到firebase firestore数据库中,当我运行该函数时,我得到以下错误
我的错误日志
火力基地部署
===正在部署到“borsa-app-f6921”...
i部署函数运行命令:npm --前缀“$RESOURCE_DIR”运行lint

  1. > lint
  2. > eslint .
  3. + functions: Finished running predeploy script.
  4. i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
  5. i functions: ensuring required API cloudbuild.googleapis.com is enabled...
  6. i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
  7. + artifactregistry: required API artifactregistry.googleapis.com is enabled
  8. + functions: required API cloudbuild.googleapis.com is enabled
  9. + functions: required API cloudfunctions.googleapis.com is enabled
  10. i functions: preparing codebase default for deployment
  11. ! functions: package.json indicates an outdated version of firebase-functions.
  12. Please upgrade-using npm install --save firebase-functions@latest in your functions directory.
  13. ! functions: Please note that there will be breaking changes when you upgrade.
  14. i functions: preparing functions directory for uploading...
  15. i functions: packaged C:\Users\yusuf\Desktop\bulut-fonksiyonlari\functions
  16. (75.69 KB) for uploading
  17. + functions: functions folder uploaded successfully
  18. The following functions are found in your project but do not exist in your local source code:
  19. myFunction(us-central1)
  20. If you are renaming a function or changing its region,
  21. it is recommended that you create the new function first before deleting the old one
  22. to prevent event loss. For more info, visit https://firebase.google.
  23. com/docs/functions/manage- functions#modify
  24. ? Would you like to proceed with deletion? Selecting no will continue the rest of
  25. the deployments. Yes
  26. i functions: creating Node.js 16 function saveDataToFirestore(us-central1)...
  27. i functions: deleting Node.js 16 function myFunction(us-central1)...
  28. + functions[myFunction(us-central1)] Successful delete operation.
  29. Build failed: ...lid: lock file's google-p12-pem@3.1.4 does not satisfy google-p12-pem@2.0.5
  30. npm ERR! Missing: node-forge@0.10.0 from lock fi le
  31. npm ERR! Missing: has-tostringtag@1.0.0 from lock file
  32. npm ERR! Invalid: lock file's yallist@4.0.0 does not satisfy yallist@3.1.1
  33. npm ERR! Missing: define-properties@1.1.4 from lock file
  34. npm ERR! Missing: has-property-descriptors@1.0.0 from lock file
  35. npm ERR! Missing: mimic-fn@2.1.0 from lock file
  36. npm ERR! Missing: duplexify@4.1.2 from lock file
  37. npm ERR! Missing: functions-have-names@1.2.3 from lock file
  38. npm ERR! Invalid: lock file's http-proxy-agent@5.0.0 does not satisfy http-proxy-agent@4.0.1
  39. npm ERR! Invalid: lock file's uuid@8.3.2 does not satisfy uuid@7.0.3
  40. npm ERR! Invalid: lock file's @tootallnate/once@2.0.0 does not satisfy @tootallnate/once@1.1.2
  41. npm ERR! Missing: is-bigint@1.0.4 from lock file
  42. npm ERR! Missing: is-boolean-object@1.1.2 from lock file
  43. npm ERR! Missing: is-number-object@1.0.7 from lock file
  44. npm ERR! Missing: is-symbol@1.0.4 from lock file
  45. npm ERR! Missing: has-bigints@1.0.2 from lock file
  46. npm ERR! Missing: is-weakmap@2.0.1 from lock file
  47. npm ERR! Missing: is-weakset@2.0.2 from lock file
  48. npm ERR! Missing: available-typed-arrays@1.0.5 from lock file
  49. npm ERR! Missing: for-each@0.3.3 from lock file
  50. npm ERR! Missing: gopd@1.0.1 from lock file
  51. npm ERR! Missing: is-typed-array@1.1.10 from lock file
  52. npm ERR! Missing: is-callable@1.2.7 from lock file
  53. npm ERR! Missing: p-try@2.2.0 from lock file
  54. npm ERR! Missing: core-util-is@1.0.3 from lock file
  55. npm ERR! Missing: isarray@1.0.0 from lock file
  56. npm ERR! Missing: process-nextick-args@2.0.1 from lock file
  57. npm ERR! Missing: safe-buffer@5.1.2 from lock file
  58. npm ERR! Missing: string_decoder@1.1.1 from lock file
  59. npm ERR! Missing: @firebase/auth-interop-types@0.1.5 from lock file
  60. npm ERR! Missing: @firebase/util@0.3.2 from lock file
  61. npm ERR! Missing: @firebase/component@0.1.19 from lock file
  62. npm ERR! Missing: @firebase/database-types@0.5.2 from lock file
  63. npm ERR! Missing: tslib@1.14.1 from lock file
  64. npm ERR! Missing: @firebase/app-types@0.6.1 from lock file
  65. npm ERR!
  66. npm ERR! Clean install a project
  67. npm ERR!
  68. npm ERR! Usage:
  69. npm ERR! npm ci
  70. npm ERR!
  71. npm ERR! Options:
  72. npm ERR! [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle]
  73. npm ERR! [-E|--save-exact] [-g|--global] [--global-style] [--legacy-bundling]
  74. npm ERR! [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
  75. npm ERR! [--strict-peer-deps] [--no-package-lock] [--foreground-scripts]
  76. npm ERR! [--ignore-scripts] [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
  77. npm ERR! [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
  78. npm ERR! [-ws|--workspaces] [--include-workspace-root] [--install-links]
  79. npm ERR!
  80. npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
  81. npm ERR!
  82. npm ERR! Run "npm help ci" for more info
  83. npm ERR! A complete log of this run can be found in:
  84. npm ERR! /www-data-home/.npm/_logs/2022-12-14T11_02_18_814Z-debug-0.log; Error ID: beaf8772
  85. Functions deploy had errors with the following functions:
  86. saveDataToFirestore(us-central1)
  87. i functions: cleaning up build files...
  88. ! functions: Unhandled error cleaning up build images. This could result in a small
  89. monthly bill if not corrected. You can attempt to delete these images
  90. by redeploying or you can delete them manually
  91. at https://console.cloud.google.com/artifacts/docker/borsa-app-f6921/us-central1/gcf-artifacts
  92. Error: There was an error deploying functions

这是我的密码

  1. const functions = require("firebase-functions");
  2. const admin = require("firebase-admin");
  3. const axios = require("axios");
  4. admin.initializeApp();
  5. const db = admin.firestore();
  6. exports.saveDataToFirestore = functions.https.onRequest((request, response) => {
  7. axios.get("https://api.coingecko.com/api/v3/coins/markets? vs_currency=usd&order
  8. =market_cap_desc&per_page=100&page=1&sparkline=true")
  9. .then((res) => {
  10. db.collection("data").add(res.data)
  11. .then(() => {
  12. response.send("successful");
  13. })
  14. .catch((err) => {
  15. response.send("Error " + err);
  16. });
  17. })
  18. .catch((err) => {
  19. response.send("Error REST API: " + err);
  20. });
  21. });
tzcvj98z

tzcvj98z1#

你能把你的节点从16改为14吗?如果可以的话,告诉我。如果14不行的话,把12或者10中的任何一个放上去。因为你使用的是firebase 8,这可能是一个兼容性问题

  1. {
  2. "name": "functions",
  3. "description": "Cloud Functions for Firebase",
  4. "scripts": {
  5. "lint": "eslint .",
  6. "serve": "firebase emulators:start --only functions",
  7. "shell": "firebase functions:shell",
  8. "start": "npm run shell",
  9. "deploy": "firebase deploy --only functions",
  10. "logs": "firebase functions:log"
  11. },
  12. "engines": {
  13. "node": "14"
  14. },
  15. "main": "index.js",
  16. "dependencies": {
  17. "firebase": "^8.10.0",
  18. "firebase-admin": "^8.13.0",
  19. "firebase-functions": "^3.14.1"
  20. },
  21. "private": true
  22. }

以下是一个可用的包. json

  1. {
  2. "name": "functions",
  3. "scripts": {
  4. "build": "tsc",
  5. "serve": "npm run build && firebase emulators:start --only functions",
  6. "shell": "npm run build && firebase functions:shell",
  7. "start": "npm run shell",
  8. "deploy": "firebase deploy --only functions",
  9. "logs": "firebase functions:log"
  10. },
  11. "engines": {
  12. "node": "12"
  13. },
  14. "main": "lib/index.js",
  15. "dependencies": {
  16. "@google-cloud/firestore": "^4.8.1",
  17. "@google-cloud/logging": "^9.2.1",
  18. "@google-cloud/storage": "^5.3.0",
  19. "@google-cloud/tasks": "^2.3.0",
  20. "@sendgrid/mail": "^7.4.2",
  21. "cors": "^2.8.5",
  22. "firebase": "^8.2.0",
  23. "firebase-admin": "^9.4.2",
  24. "firebase-functions": "^3.15.7",
  25. },
  26. "devDependencies": {
  27. "@types/firebase": "^3.2.1",
  28. "typescript": "^4.1.3"
  29. },
  30. "private": true
  31. }

你可以尝试在这里安装firebase,firebase-admin和firebase-functions的版本,这对我的项目是有效的。我可以部署这些函数。在部署之前执行npm install
按如下所示更新函数

  1. exports.saveDataToFirestore = functions.https.onRequest((request, response) => {
  2. axios.get("https://api.coingecko.com/api/v3/coins/markets? vs_currency=usd&order
  3. =market_cap_desc&per_page=100&page=1&sparkline=true")
  4. .then((res) => {
  5. console.log("res.data", res.data); // make sure you check logs for this, you have make sure you res.data is not undefined
  6. // we need a unique identified, I will use timestamps
  7. const id = new Date().getTime(); // this will be unique
  8. db.collection("data").doc(id).set(res.data,{merge: false}) // this will create a new doc
  9. .then(() => {
  10. response.send("successful");
  11. })
  12. .catch((err) => {
  13. response.send("Error " + err);
  14. });
  15. })
  16. .catch((err) => {
  17. response.send("Error REST API: " + err);
  18. });
  19. });
展开查看全部

相关问题