部署 Firebase 计划函数错误:“async_hooks_1.AsyncLocalStorage 不是构造函数”

问题描述 投票:0回答:1

我在将“计划功能”部署到 Firebase 时遇到一些问题。这是我的问题之一。 在功能部署时,我可以捕获(我认为的)主要错误原因:

Detailed stack trace: TypeError: async_hooks_1.AsyncLocalStorage is not a constructor

index.js

const functions = require("firebase-functions"); const admin = require("firebase-admin"); admin.initializeApp(); exports.scheduledFunction = functions.pubsub .schedule("45 8 * * *") .timeZone("America/Sao_Paulo") .onRun(() => { console.log("Triggering email") return null; });

部署

% firebase deploy --only functions === Deploying to '****'... i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint > functions@ lint ****/functions > eslint . ✔ functions: Finished running predeploy script. i functions: preparing codebase default for deployment i functions: ensuring required API cloudfunctions.googleapis.com is enabled... i functions: ensuring required API cloudbuild.googleapis.com is enabled... i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled... ✔ artifactregistry: required API artifactregistry.googleapis.com is enabled ✔ functions: required API cloudfunctions.googleapis.com is enabled ✔ functions: required API cloudbuild.googleapis.com is enabled i functions: preparing functions directory for uploading... i functions: packaged ****/functions (41.84 KB) for uploading i functions: ensuring required API cloudscheduler.googleapis.com is enabled... ✔ functions: required API cloudscheduler.googleapis.com is enabled ✔ functions: functions folder uploaded successfully The following functions are found in your project but do not exist in your local source code: listenReserveCreated(us-central1) If you are renaming a function or changing its region, it is recommended that you create the new function first before deleting the old one to prevent event loss. For more info, visit https://firebase.google.com/docs/functions/manage-functions#modify ? Would you like to proceed with deletion? Selecting no will continue the rest of the deployments. No i functions: updating Node.js 10 function scheduledFunction(us-central1)... Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation. Functions deploy had errors with the following functions: scheduledFunction(us-central1) i functions: cleaning up build files... Error: There was an error deploying functions

日志:

% gcloud functions logs read scheduledFunction LEVEL NAME EXECUTION_ID TIME_UTC LOG E scheduledFunction 2023-03-17 12:36:18.077 Function cannot be initialized. Error: function terminated. Recommended action: inspect logs for termination reason. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging scheduledFunction csgypxon04g7 2023-03-17 12:36:17.539 Could not load the function, shutting down. scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 at Module._compile (internal/modules/cjs/loader.js:778:30) scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 at Object.<anonymous> (/workspace/node_modules/firebase-functions/lib/logger/index.js:26:17) scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 at require (internal/modules/cjs/helpers.js:25:18) scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 at Module.require (internal/modules/cjs/loader.js:692:17) scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 at Function.Module._load (internal/modules/cjs/loader.js:585:3) scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 at tryModuleLoad (internal/modules/cjs/loader.js:593:12) scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 at Module.load (internal/modules/cjs/loader.js:653:32) scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 at Module._compile (internal/modules/cjs/loader.js:778:30) scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 at Object.<anonymous> (/workspace/node_modules/firebase-functions/lib/common/trace.js:6:24) scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 Detailed stack trace: TypeError: async_hooks_1.AsyncLocalStorage is not a constructor scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 Is there a syntax error in your code? scheduledFunction csgypxon04g7 2023-03-17 12:36:17.538 Provided module can't be loaded. E scheduledFunction 2023-03-17 12:27:24.077 Function cannot be initialized. Error: function terminated. Recommended action: inspect logs for termination reason. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging scheduledFunction vfj9lv1lxvmm 2023-03-17 12:27:22.993 Could not load the function, shutting down. scheduledFunction vfj9lv1lxvmm 2023-03-17 12:27:22.992 at Module._compile (internal/modules/cjs/loader.js:778:30) scheduledFunction vfj9lv1lxvmm 2023-03-17 12:27:22.992 at Object.<anonymous> (/workspace/node_modules/firebase-functions/lib/logger/index.js:26:17) scheduledFunction vfj9lv1lxvmm 2023-03-17 12:27:22.992 at require (internal/modules/cjs/helpers.js:25:18)

	
javascript node.js firebase google-cloud-functions async-hooks
1个回答
1
投票

i functions: updating Node.js 10 function scheduledFunction(us-central1)...

根据 

Firebase Admin SDK 先决条件

确保您的服务器根据您使用的 Admin SDK 运行以下命令:

管理 Node.js SDK — Node.js 14+
请告诉我更新 Node.js 版本后问题是否仍然存在。

© www.soinside.com 2019 - 2024. All rights reserved.