[英]Firebase cloud functions error (TypeError: Cannot read property 'data' of undefined)
[英]When deploying firebase cloud functions I get: Build failed: npm ERR! Cannot read property '@babel/core' of undefined
这是我过去 3 天在部署云功能时收到的一系列非常令人沮丧的错误中的最新错误。
部署时我得到:
firebase deploy --only "functions:retireAtlistedEvents,functions:enqueueAtlistedEventsToRetire"
=== Deploying to 'my-project'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build
> build
> tsc
✔ functions: Finished running predeploy script.
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 codebase default for deployment
i functions: preparing functions directory for uploading...
i functions: packaged /home/wpghijsen/Programs/combinedInstance/treetopCombined/treetoprules/functions (188.31 KB) for uploading
i functions: ensuring required API cloudscheduler.googleapis.com is enabled...
i functions: ensuring required API cloudtasks.googleapis.com is enabled...
✔ functions: required API cloudscheduler.googleapis.com is enabled
✔ functions: required API cloudtasks.googleapis.com is enabled
✔ functions: functions folder uploaded successfully
i functions: updating Node.js 14 function enqueueAtlistedEventsToRetire(us-central1)...
i functions: updating Node.js 14 function retireAtlistedEvents(us-central1)...
Build failed: npm ERR! Cannot read property '@babel/core' of undefined
npm ERR! A complete log of this run can be found in:
npm ERR! /www-data-home/.npm/_logs/2022-12-03T21_14_11_382Z-debug.log; Error ID: beaf8772
Build failed: npm ERR! Cannot read property '@babel/core' of undefined
npm ERR! A complete log of this run can be found in:
npm ERR! /www-data-home/.npm/_logs/2022-12-03T21_14_54_517Z-debug.log; Error ID: beaf8772
Functions deploy had errors with the following functions:
enqueueAtlistedEventsToRetire(us-central1)
retireAtlistedEvents(us-central1)
i functions: cleaning up build files...
Error: There was an error deploying functions:
- Error Failed to update function enqueueAtlistedEventsToRetire in region us-central1
- Error Failed to update function retireAtlistedEvents in region us-central1
我做了 --debug 选项并在失败前得到了 output
https://artifactregistry.googleapis.com/v1beta2/projects/my-project/locations/us-central1/repositories/gcf-artifacts/packages/upsert_pro_event_info_in_typesense 404
[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"}}
[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
[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"}}
[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
[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"}}
[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
[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"}}
[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
[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"}}
[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
[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"}}
[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
[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"}}
[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
[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"}}
[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
[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"}}
[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
[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"}}
[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
[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"}}
[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
[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"}}
[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
[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"}}
[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
[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"}}
[2022-12-03T21:49:54.785Z] Functions deploy failed.
[2022-12-03T21:49:54.785Z] {
"endpoint": {
"id": "enqueueAtlistedEventsToRetire",
"project": "my-project",
"region": "us-central1",
"entryPoint": "enqueueAtlistedEventsToRetire",
"platform": "gcfv1",
"runtime": "nodejs14",
"scheduleTrigger": {
"schedule": "0,15,30,45 * * * *",
"timeZone": null,
"retryConfig": {
"maxBackoffSeconds": null,
"minBackoffSeconds": null,
"maxRetrySeconds": null,
"retryCount": null,
"maxDoublings": null
}
},
"labels": {
"deployment-tool": "cli-firebase"
},
"serviceAccount": null,
"ingressSettings": null,
"availableMemoryMb": 2048,
"timeoutSeconds": null,
"maxInstances": null,
"minInstances": null,
"vpc": null,
"environmentVariables": {
"FIREBASE_CONFIG": "{\"projectId\":\"my-project\",\"databaseURL\":\"https://my-project.firebaseio.com\",\"storageBucket\":\"my-project.appspot.com\",\"locationId\":\"us-central\"}",
"GCLOUD_PROJECT": "my-project",
"EVENTARC_CLOUD_EVENT_SOURCE": "projects/my-project/locations/us-central1/functions/upsertProEventInfoInTypesense"
},
"codebase": "default",
"securityLevel": "SECURE_ALWAYS",
"targetedByOnly": true,
"hash": "2a1b0fcfaf7a46ed932b2b3e5eea8f11c62140c5"
},
"op": "update",
"original": {
"name": "FirebaseError",
"children": [],
"exit": 1,
"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",
"status": 3
}
}
[2022-12-03T21:49:54.785Z] {
"endpoint": {
"id": "retireAtlistedEvents",
"project": "my-project",
"region": "us-central1",
"entryPoint": "retireAtlistedEvents",
"platform": "gcfv1",
"runtime": "nodejs14",
"taskQueueTrigger": {
"rateLimits": {
"maxConcurrentDispatches": 6,
"maxDispatchesPerSecond": null
},
"retryConfig": {
"maxAttempts": 5,
"maxBackoffSeconds": null,
"minBackoffSeconds": 60,
"maxRetrySeconds": null,
"maxDoublings": null
}
},
"serviceAccount": null,
"ingressSettings": null,
"availableMemoryMb": 2048,
"timeoutSeconds": null,
"maxInstances": null,
"minInstances": null,
"vpc": null,
"environmentVariables": {
"FIREBASE_CONFIG": "{\"projectId\":\"my-project\",\"databaseURL\":\"https://my-project.firebaseio.com\",\"storageBucket\":\"my-project.appspot.com\",\"locationId\":\"us-central\"}",
"GCLOUD_PROJECT": "my-project",
"EVENTARC_CLOUD_EVENT_SOURCE": "projects/my-project/locations/us-central1/functions/upsertProEventInfoInTypesense"
},
"codebase": "default",
"securityLevel": "SECURE_OPTIONAL",
"targetedByOnly": true,
"hash": "2a1b0fcfaf7a46ed932b2b3e5eea8f11c62140c5",
"labels": {
"deployment-tool": "cli-firebase"
}
},
"op": "update",
"original": {
"name": "FirebaseError",
"children": [],
"exit": 1,
"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",
"status": 3
}
}
Error: There was an error deploying functions:
- Error Failed to update function enqueueAtlistedEventsToRetire in region us-central1
- Error Failed to update function retireAtlistedEvents in region us-central1
这是我的 package.json 文件:
{
"name": "functions",
"type": "module",
"scripts": {
"build": "tsc",
"emulators:start": "firebase emulators:start",
"emulators:stop": "lsof -t -i:5000 -i:5001 -i:4030 -i:9099 -i:9001 -i:9199 -i:8091 -i:9090 | xargs kill -9",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"test": "mocha --reporter spec --timeout 10000",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "14"
},
"main": "lib/index.js",
"dependencies": {
"@babel/core": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"@babel/runtime": "^7.2.0",
"@firebase/app-compat": "^0.1.28",
"@google-cloud/tasks": "^3.0.5",
"@types/rimraf": "^3.0.2",
"acorn": "^8.8.1",
"axios": "^0.27.2",
"chai": "^4.3.4",
"csv-parse": "^5.2.1",
"firebase-admin": "^11.3.0",
"firebase-functions": "^4.1.0",
"fs": "0.0.1-security",
"mocha": "^9.1.3",
"puppeteer": "^10.4.0",
"rimraf": "^3.0.2",
"typescript": "4.3.5",
"typesense": "^1.3.0"
},
"devDependencies": {
"firebase-functions-test": "^0.3.3"
},
"private": true
}
请注意,我也尝试了最新版本的@babel 依赖项(不是新的)但没有成功。
供您参考,这里是我正在部署的云功能:
export const retireAtlistedEvents = functions
.runWith( { memory: '2GB' })
.tasks.taskQueue({
retryConfig: {
maxAttempts: 5,
minBackoffSeconds: 60,
},
rateLimits: {
maxConcurrentDispatches: 6,
},
}).onDispatch(async (data) => {
const minEvent = data.minEvent as MinEventInfo;
functions.logger.log("THIS IS retireAtlistedEvents minEventsData Success minEvent", minEvent);
});
export const enqueueAtlistedEventsToRetire = functions
.runWith( { memory: '2GB' })
.pubsub
.schedule('0,15,30,45 * * * *').onRun(async context => {
const queue = getFunctions().taskQueue("retireAtlistedEvents");
const enqueues = [];
let minEvent: MinEventInfo = {
proId: "abcd",
eventId: "efgh"
}
enqueues.push(
queue.enqueue({minEvent: minEvent}, {
dispatchDeadlineSeconds: 20 // 20 seconds
}),
);
await Promise.all(enqueues)
.then(() => {
const exit: ExtendedExitMessage = {
exit: 0,
message: "enqueueAtlistedEventsToRetire success",
success: true,
};
return exit;
})
.catch(() => {
const exit: ExtendedExitMessage = {
exit: 1,
message: "enqueueAtlistedEventsToRetire success",
success: false,
};
return exit;
});
});
我认为可能存在类似 v1 v2 不匹配的问题,我一直在阅读相关内容。 但是,我试图将所有内容都保留为 v1,当我将 go 用于我的云功能时,上面的所有功能都表示 v1。
任何帮助深表感谢。
该错误可能是由于错误日志中提到的属性 package 安装时出现的问题,对于这种情况,它是babel core package ,它显示为未定义,为了防止这种情况,您可以尝试重新安装 package 作为以下:
npm install @babel/core --save
检查类似的例子:
这是我发现的唯一一篇描述我昨天花了大部分时间试图解决的确切问题的帖子。
我最终尝试只部署项目的一个 function 以更好地了解调试日志中到底发生了什么。 我发现一行“找不到函数。yaml。必须使用 http 发现”。
谷歌搜索在这里找到了一个相邻的 SO 主题,他们建议在部署之前删除 package-lock.json。
我这样做了,而且效果很好。 基本上,package.lock 中的包与 package.json 中描述的一些依赖项之间存在断开连接,这让 Firebase 变得胡思乱想。
不会假装拥有所有“为什么”的答案,但删除包锁为我解决了这个确切的问题,我不希望其他人面对这个没有解决方案!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.