部署 firebase 云功能时,我得到: Build failed: npm ERR! 无法读取未定义的属性“@babel/core”

Wil*_*sen 6 npm firebase google-cloud-functions babel-core

这是过去三天我在部署云功能时收到的一系列非常令人沮丧的错误中的最新一个。

\n

部署时我得到:

\n
firebase deploy --only "functions:retireAtlistedEvents,functions:enqueueAtlistedEventsToRetire"\n\n=== Deploying to 'my-project'...\n\ni  deploying functions\nRunning command: npm --prefix "$RESOURCE_DIR" run build\n\n> build\n> tsc\n\n\xe2\x9c\x94  functions: Finished running predeploy script.\ni  functions: ensuring required API cloudfunctions.googleapis.com is enabled...\ni  functions: ensuring required API cloudbuild.googleapis.com is enabled...\ni  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...\n\xe2\x9c\x94  artifactregistry: required API artifactregistry.googleapis.com is enabled\n\xe2\x9c\x94  functions: required API cloudfunctions.googleapis.com is enabled\n\xe2\x9c\x94  functions: required API cloudbuild.googleapis.com is enabled\ni  functions: preparing codebase default for deployment\ni  functions: preparing functions directory for uploading...\ni  functions: packaged /home/wpghijsen/Programs/combinedInstance/treetopCombined/treetoprules/functions (188.31 KB) for uploading\ni  functions: ensuring required API cloudscheduler.googleapis.com is enabled...\ni  functions: ensuring required API cloudtasks.googleapis.com is enabled...\n\xe2\x9c\x94  functions: required API cloudscheduler.googleapis.com is enabled\n\xe2\x9c\x94  functions: required API cloudtasks.googleapis.com is enabled\n\xe2\x9c\x94  functions: functions folder uploaded successfully\ni  functions: updating Node.js 14 function enqueueAtlistedEventsToRetire(us-central1)...\ni  functions: updating Node.js 14 function retireAtlistedEvents(us-central1)...\nBuild failed: npm ERR! Cannot read property '@babel/core' of undefined\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /www-data-home/.npm/_logs/2022-12-03T21_14_11_382Z-debug.log; Error ID: beaf8772\nBuild failed: npm ERR! Cannot read property '@babel/core' of undefined\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /www-data-home/.npm/_logs/2022-12-03T21_14_54_517Z-debug.log; Error ID: beaf8772\n\nFunctions deploy had errors with the following functions:\n    enqueueAtlistedEventsToRetire(us-central1)\n    retireAtlistedEvents(us-central1)\ni  functions: cleaning up build files...\nError: There was an error deploying functions:\n- Error Failed to update function enqueueAtlistedEventsToRetire in region us-central1\n- Error Failed to update function retireAtlistedEvents in region us-central1\n\n
Run Code Online (Sandbox Code Playgroud)\n

我执行了 --debug 选项并在失败之​​前得到了输出

\n
https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/upsert_pro_event_info_in_typesense 404\n[2022-12-03T21:49:54.764Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/upsert_pro_event_info_in_typesense {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/upsert_pro_event_info_in_typesense\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.766Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/set_users_geo_coded_address_data 404\n[2022-12-03T21:49:54.766Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/set_users_geo_coded_address_data {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/set_users_geo_coded_address_data\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.767Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/retire_atlisted_events 404\n[2022-12-03T21:49:54.767Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/retire_atlisted_events {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/retire_atlisted_events\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.769Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/pro_cancel_atlisted_pro_event 404\n[2022-12-03T21:49:54.770Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/pro_cancel_atlisted_pro_event {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/pro_cancel_atlisted_pro_event\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.776Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/archive_chat 404\n[2022-12-03T21:49:54.776Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/archive_chat {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/archive_chat\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.778Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/initialize_chat 404\n[2022-12-03T21:49:54.778Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/initialize_chat {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/initialize_chat\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.779Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/is_atlisted_and_claimed_cloud_fxn 404\n[2022-12-03T21:49:54.779Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/is_atlisted_and_claimed_cloud_fxn {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/is_atlisted_and_claimed_cloud_fxn\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.780Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/schedule_manage_format_initial_atlisted_data 404\n[2022-12-03T21:49:54.780Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/schedule_manage_format_initial_atlisted_data {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/schedule_manage_format_initial_atlisted_data\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.781Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/request_multiple_atlisted_pro_events 404\n[2022-12-03T21:49:54.781Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/request_multiple_atlisted_pro_events {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/request_multiple_atlisted_pro_events\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.781Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/get_at_listed_doc_count 404\n[2022-12-03T21:49:54.781Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/get_at_listed_doc_count {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/get_at_listed_doc_count\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.783Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/adjust_atlisted_pro_event_open_slots_cloud_fxn 404\n[2022-12-03T21:49:54.783Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/adjust_atlisted_pro_event_open_slots_cloud_fxn {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/adjust_atlisted_pro_event_open_slots_cloud_fxn\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.783Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/remove_request_multiple_atlisted_pro_events 404\n[2022-12-03T21:49:54.783Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/remove_request_multiple_atlisted_pro_events {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/remove_request_multiple_atlisted_pro_events\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.784Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/schedule_scrape 404\n[2022-12-03T21:49:54.784Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/schedule_scrape {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/schedule_scrape\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.784Z] <<< [apiv2][status] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/update_user_info_in_typesense 404\n[2022-12-03T21:49:54.784Z] <<< [apiv2][body] DELETE https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/update_user_info_in_typesense {"error":{"code":404,"message":"Package \\"projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/update_user_info_in_typesense\\" was not found.","status":"NOT_FOUND"}}\n[2022-12-03T21:49:54.785Z] Functions deploy failed.\n[2022-12-03T21:49:54.785Z] {\n  "endpoint": {\n    "id": "enqueueAtlistedEventsToRetire",\n    "project": "my-project",\n    "region": "us-central1",\n    "entryPoint": "enqueueAtlistedEventsToRetire",\n    "platform": "gcfv1",\n    "runtime": "nodejs14",\n    "scheduleTrigger": {\n      "schedule": "0,15,30,45 * * * *",\n      "timeZone": null,\n      "retryConfig": {\n        "maxBackoffSeconds": null,\n        "minBackoffSeconds": null,\n        "maxRetrySeconds": null,\n        "retryCount": null,\n        "maxDoublings": null\n      }\n    },\n    "labels": {\n      "deployment-tool": "cli-firebase"\n    },\n    "serviceAccount": null,\n    "ingressSettings": null,\n    "availableMemoryMb": 2048,\n    "timeoutSeconds": null,\n    "maxInstances": null,\n    "minInstances": null,\n    "vpc": null,\n    "environmentVariables": {\n      "FIREBASE_CONFIG": "{\\"projectId\\":\\"my-project\\",\\"databaseURL\\":\\"https://my-project.firebaseio.com\\",\\"storageBucket\\":\\"my-project.appspot.com\\",\\"locationId\\":\\"us-central\\"}",\n      "GCLOUD_PROJECT": "my-project",\n      "EVENTARC_CLOUD_EVENT_SOURCE": "projects/my-project/locations/us-central1/functions/upsertProEventInfoInTypesense"\n    },\n    "codebase": "default",\n    "securityLevel": "SECURE_ALWAYS",\n    "targetedByOnly": true,\n    "hash": "2a1b0fcfaf7a46ed932b2b3e5eea8f11c62140c5"\n  },\n  "op": "update",\n  "original": {\n    "name": "FirebaseError",\n    "children": [],\n    "exit": 1,\n    "message": "Build failed: npm ERR! Cannot read property '@babel/core' of undefined\\n\\nnpm ERR! A complete log of this run can be found in:\\nnpm ERR!     /www-data-home/.npm/_logs/2022-12-03T21_49_11_956Z-debug.log; Error ID: beaf8772",\n    "status": 3\n  }\n}\n[2022-12-03T21:49:54.785Z] {\n  "endpoint": {\n    "id": "retireAtlistedEvents",\n    "project": "my-project",\n    "region": "us-central1",\n    "entryPoint": "retireAtlistedEvents",\n    "platform": "gcfv1",\n    "runtime": "nodejs14",\n    "taskQueueTrigger": {\n      "rateLimits": {\n        "maxConcurrentDispatches": 6,\n        "maxDispatchesPerSecond": null\n      },\n      "retryConfig": {\n        "maxAttempts": 5,\n        "maxBackoffSeconds": null,\n        "minBackoffSeconds": 60,\n        "maxRetrySeconds": null,\n        "maxDoublings": null\n      }\n    },\n    "serviceAccount": null,\n    "ingressSettings": null,\n    "availableMemoryMb": 2048,\n    "timeoutSeconds": null,\n    "maxInstances": null,\n    "minInstances": null,\n    "vpc": null,\n    "environmentVariables": {\n      "FIREBASE_CONFIG": "{\\"projectId\\":\\"my-project\\",\\"databaseURL\\":\\"https://my-project.firebaseio.com\\",\\"storageBucket\\":\\"my-project.appspot.com\\",\\"locationId\\":\\"us-central\\"}",\n      "GCLOUD_PROJECT": "my-project",\n      "EVENTARC_CLOUD_EVENT_SOURCE": "projects/my-project/locations/us-central1/functions/upsertProEventInfoInTypesense"\n    },\n    "codebase": "default",\n    "securityLevel": "SECURE_OPTIONAL",\n    "targetedByOnly": true,\n    "hash": "2a1b0fcfaf7a46ed932b2b3e5eea8f11c62140c5",\n    "labels": {\n      "deployment-tool": "cli-firebase"\n    }\n  },\n  "op": "update",\n  "original": {\n    "name": "FirebaseError",\n    "children": [],\n    "exit": 1,\n    "message": "Build failed: npm ERR! Cannot read property '@babel/core' of undefined\\n\\nnpm ERR! A complete log of this run can be found in:\\nnpm ERR!     /www-data-home/.npm/_logs/2022-12-03T21_49_36_419Z-debug.log; Error ID: beaf8772",\n    "status": 3\n  }\n}\nError: There was an error deploying functions:\n- Error Failed to update function enqueueAtlistedEventsToRetire in region us-central1\n- Error Failed to update function retireAtlistedEvents in region us-central1\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的 package.json 文件:

\n
{\n  "name": "functions",\n  "type": "module",\n  "scripts": {\n    "build": "tsc",\n    "emulators:start": "firebase emulators:start",\n    "emulators:stop": "lsof -t -i:5000 -i:5001 -i:4030 -i:9099 -i:9001 -i:9199 -i:8091 -i:9090 | xargs kill -9",\n    "serve": "npm run build && firebase emulators:start --only functions",\n    "shell": "npm run build && firebase functions:shell",\n    "start": "npm run shell",\n    "test": "mocha --reporter spec --timeout 10000",\n    "deploy": "firebase deploy --only functions",\n    "logs": "firebase functions:log"\n  },\n  "engines": {\n    "node": "14"\n  },\n  "main": "lib/index.js",\n  "dependencies": {\n    "@babel/core": "^7.2.0",\n    "@babel/preset-env": "^7.2.0",\n    "@babel/runtime": "^7.2.0",\n    "@firebase/app-compat": "^0.1.28",\n    "@google-cloud/tasks": "^3.0.5",\n    "@types/rimraf": "^3.0.2",\n    "acorn": "^8.8.1",\n    "axios": "^0.27.2",\n    "chai": "^4.3.4",\n    "csv-parse": "^5.2.1",\n    "firebase-admin": "^11.3.0",\n    "firebase-functions": "^4.1.0",\n    "fs": "0.0.1-security",\n    "mocha": "^9.1.3",\n    "puppeteer": "^10.4.0",\n    "rimraf": "^3.0.2",\n    "typescript": "4.3.5",\n    "typesense": "^1.3.0"\n  },\n  "devDependencies": {\n    "firebase-functions-test": "^0.3.3"\n  },\n  "private": true\n}\n\n\n
Run Code Online (Sandbox Code Playgroud)\n

请注意,我还尝试了最新版本的 @babel 依赖项(并没有更新多少),但没有成功。

\n

以下是我正在部署的云功能,供您参考:

\n
export const retireAtlistedEvents = functions\n    .runWith( { memory: '2GB' })\n    .tasks.taskQueue({\n      retryConfig: {\n        maxAttempts: 5,\n        minBackoffSeconds: 60,\n      },\n      rateLimits: {\n        maxConcurrentDispatches: 6,\n      },\n    }).onDispatch(async (data) => {\n      const minEvent = data.minEvent as MinEventInfo;\n\n      functions.logger.log("THIS IS retireAtlistedEvents minEventsData Success minEvent", minEvent);\n\n     });\n\n    export const enqueueAtlistedEventsToRetire = functions\n    .runWith( { memory: '2GB' })\n    .pubsub\n    .schedule('0,15,30,45 * * * *').onRun(async context => {\n        const queue = getFunctions().taskQueue("retireAtlistedEvents");\n      \n        const enqueues = [];\n\n        let minEvent: MinEventInfo = {\n          proId: "abcd",\n          eventId: "efgh"\n        }\n\n        enqueues.push(\n          queue.enqueue({minEvent: minEvent}, {\n              dispatchDeadlineSeconds: 20 // 20 seconds\n          }),\n        );\n\n\n        await Promise.all(enqueues)\n          .then(() => {\n            const exit: ExtendedExitMessage = {\n              exit: 0,\n              message: "enqueueAtlistedEventsToRetire success",\n              success: true,\n            };\n            return exit;\n          })\n          .catch(() => {\n            const exit: ExtendedExitMessage = {\n              exit: 1,\n              message: "enqueueAtlistedEventsToRetire success",\n              success: false,\n            };\n            return exit;\n          });\n     \n      });\n\n
Run Code Online (Sandbox Code Playgroud)\n

我认为可能存在类似 v1 v2 不匹配的情况,我一直在阅读相关内容。但是,我试图保留所有内容 v1,当我转到我的云功能时,那里的所有内容都显示上述功能的 v1。

\n

任何帮助深表感谢。

\n

Mat*_*t S 17

这是我发现的唯一一篇描述我昨天花了大部分时间试图解决的问题的帖子。

我最终尝试仅部署项目的单个函数,以更好地了解调试日志中到底发生了什么。我发现一行“找不到functions.yaml。必须使用http discovery”。

谷歌搜索发现了一个类似的相邻 SO 主题here,他们建议在部署之前删除 package-lock.json。

我这样做了,而且效果很好。基本上,package.lock 中的包与 package.json 中描述的一些依赖项之间存在脱节,这使得 Firebase 变得脾气暴躁。

不会假装拥有所有“为什么”的答案,但删除包锁为我解决了这个确切的问题,我不希望其他人面对这个问题没有解决方案!

  • 08/07/2023,我特此确认这绝对仍然有效。10 分(满分 10 分) (2认同)

小智 0

该错误可能是由于错误日志中提到的属性的包安装时出现的问题,在这种情况下,它是babel core 包,显示为未定义,为了防止这种情况,您可以尝试重新安装该包:以下:

npm install @babel/core --save

检查类似的例子: