繁体   English   中英

Firebase - 部署功能时出错 - 代码:3、Function 加载用户代码失败

[英]Firebase - There was an error deploying functions - code: 3, Function failed on loading user code

我在这个项目中工作了几个月,我在部署到 firebase 时没有遇到任何问题。我只是想更新一些在 Angular 中开发的 Web 应用程序,它托管在 firebase 中。现在每次我尝试部署时,我都会收到以下错误:

错误:部署函数时出错

我在函数文件夹中的 package.json 中的依赖项:

"dependencies": {
    "@sendgrid/mail": "^7.2.1",
    "@types/node": "^14.0.18",
    "egoiSdk": "github:E-goi/sdk-javascript",
    "firebase-admin": "^8.6.0",
    "firebase-functions": "^3.3.0",
    "mailchimp-api-v3": "^1.14.0"
  },

functions文件夹外的那个:

 "dependencies": {
        "@angular/animations": "~8.2.4",
        "@angular/common": "~8.2.4",
        "@angular/compiler": "~8.2.4",
        "@angular/core": "~8.2.4",
        "@angular/forms": "~8.2.4",
        "@angular/platform-browser": "~8.2.4",
        "@angular/platform-browser-dynamic": "~8.2.4",
        "@angular/router": "~8.2.4",
        "@fortawesome/angular-fontawesome": "^0.5.0",
        "@fortawesome/fontawesome-svg-core": "^1.2.27",
        "@fortawesome/free-solid-svg-icons": "^5.12.1",
        "@sendgrid/mail": "^7.2.1",
        "bootstrap": "^4.4.1",
        "firebase": "^8.2.4",
        "firebase-admin": "^9.2.0",
        "firebase-functions": "^3.11.0",
        "jquery": "^3.5.1",
        "mailchimp-api-v3": "^1.14.0",
        "ngx-facebook": "^3.0.0-0",
        "ngx-pagination": "^5.0.0",
        "popper.js": "^1.16.1",
        "rxjs": "~6.4.0",
        "tslib": "^1.11.1",
        "zone.js": "~0.9.1"
    },
    "devDependencies": {
        "@angular-devkit/build-angular": "^0.803.24",
        "@angular/cli": "^8.3.25",
        "@angular/compiler-cli": "~8.2.4",
        "@angular/language-service": "~8.2.4",
        "@types/jasmine": "~3.3.8",
        "@types/jasminewd2": "~2.0.3",
        "@types/node": "~8.9.4",
        "codelyzer": "^5.0.0",
        "jasmine-core": "~3.4.0",
        "jasmine-spec-reporter": "~4.2.1",
        "karma": "~4.1.0",
        "karma-chrome-launcher": "~2.2.0",
        "karma-coverage-istanbul-reporter": "~2.0.1",
        "karma-jasmine": "~2.0.1",
        "karma-jasmine-html-reporter": "^1.5.2",
        "protractor": "^5.4.3",
        "ts-node": "~7.0.0",
        "tslint": "~5.15.0",
        "typescript": "~3.5.3"
    },

和功能日志:

{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":
{"code":3,"message":"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."},"authenticationInfo": 
{"principalEmail":"example@example.com"},
"serviceName":"cloudfunctions.googleapis.com",
"methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction",
"resourceName":"projects/my-project/locations/us-central1/functions/newSubscriber"} 

我在 index.ts 上设置的函数:

admin.initializeApp(functions.config().firebase);
admin.firestore().settings({ timestampsInSnapshots: true });

const defaultClient = egoiSdk.ApiClient.instance;
const Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = "API_KEY";


exports.newSubscriber = functions.firestore.document('subscribers/{subscriberID}')
  .onCreate((snap, context) => {   

    const apiInstance = new egoiSdk.ContactsApi();
    const listId = 1; // Number | ID of the list where the contact belongs
    const contactBaseExtra = new egoiSdk.ContactBaseExtra(
      {
        "base":
        {
          "status": "active",
          "first_name": "Name",
          "language": "pt",
          "email": "example@example.com",
        }
      }
    ); 


    const callback = (error: any, data: any, response: any) => {
      if (error) {
        //console.log('ERRO AQUI');
        //console.error('ERRO AQUI!!!: ', error);
      } else {
        //console.log('API called successfully. Returned data: ' + data);
      }
    };
    apiInstance.createContact(listId, contactBaseExtra, callback);
  });

为什么会这么头疼呢? 我已经尝试过我能找到的解决方案。 我删除了两个 node_modules 文件夹,安装,重新安装,更新版本,什么都没有。 package 有问题,但最终也修复了它。 我不知道还能做什么。 有人对如何解决这个问题有建议吗?

任何形式的帮助表示赞赏!

编辑:我还没有解决这个问题,但我使用firebase deploy --exclude functions做了一个解决方法

最好的祝福。

根据错误,如此处所示,如果未正确指定代码的入口点(即导出的 function 名称),云功能部署可能会失败。 您的源代码必须包含一个入口点 function,该入口点已通过 Cloud Console 或 Cloud SDK 在您的部署中正确指定。

import * as functions from 'firebase-functions';

就我而言,我正在创建这样的触发器。

export const sendChatNotifications = functions.database
  .ref('/messages')
  .onWrite(() => {
    console.log('-------sendChatNotifications-----------');
  });

但下面给出了正确的方法,它对我有用。

exports.newChat = functions.firestore
  .document('messages/{docId}')
  .onWrite((change, context) => {
    console.log('-------sendChatNotifications-----------');
  });

有关详细信息,您可以通过运行此命令来跟踪问题。

firebase 功能:日志

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM