node.js – Firebase函数无法部署:SyntaxError:意外的令牌函数

我正在尝试将一个函数部署到firebase,我在部署期间遇到错误

错误功能未正确部署.

它可以与异步函数链接吗?

实际行为
函数部署时出错,cli向我显示以下消息:

================ console log ================

> eslint .
✔  functions: Finished running predeploy script.
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (56.39 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: updating function sendContactEmailOAuth...
⚠  functions[sendContactEmailOAuth]: Deployment error.
Function load error: Code in file index.js can't be loaded.
Is there a Syntax error in your code?
Detailed stack trace: /user_code/index.js:13
 async function getJwt() {
       ^^^^^^^^

================函数index.js文件================

const functions = require('firebase-functions');


const admin = require('firebase-admin');
   admin.initializeApp();

   const { JWT } = require('google-auth-library/build/src/index');

   exports.sendContactEmailOAuth = functions.https.onRequest((req,res) => {
 const sender_msg = 'just a test'
 const email = 'contact@lechorodescharentes.org'

 async function getJwt() {
   const client = new JWT(
     functions.config().service_key.client_email,null,functions.config().service_key.private_key,['https://www.googleapis.com/auth/cloud-platform','https://mail.google.com'],);
     await client.authorize();
      const url = `https://www.googleapis.com/dns/v1/projects/${functions.config().service_key.project_id}`;
   const res = await client.request({ url });
   console.log(res.data);
 }

getJwt();

  /*  send email with nodemailer to be inserted here */
 });

================ package.json文件================

{
 "name": "functions","description": "Cloud Functions for Firebase","scripts": {
   "lint": "eslint .","serve": "firebase serve --only functions","shell": "firebase functions:shell","start": "npm run shell","deploy": "firebase deploy --only functions","logs": "firebase functions:log"
 },"dependencies": {
   "firebase-admin": "~5.12.0","firebase-functions": "^1.0.2","firebase-tools": "^3.18.4","google-auth-library": "^1.4.0","nodemailer": "^4.6.4"
 },"devDependencies": {
   "eslint": "^4.12.0","eslint-plugin-promise": "^3.6.0"
 },"private": true
 }

解决方法

截至2018年8月:

功能现在支持节点8(8.11.1).查看this blog post.

升级到节点8

this blog post中所述,请按照以下步骤升级到节点8:

>通过npm install升级firebase-functions版本–save firebase-functions @ latest>通过npm update -g firebase-tools升级firebase-tools>在您的/functions/package.json中添加“引擎”:{“node”:“8”}

相关文章

这篇文章主要介绍“基于nodejs的ssh2怎么实现自动化部署”的...
本文小编为大家详细介绍“nodejs怎么实现目录不存在自动创建...
这篇“如何把nodejs数据传到前端”文章的知识点大部分人都不...
本文小编为大家详细介绍“nodejs如何实现定时删除文件”,内...
这篇文章主要讲解了“nodejs安装模块卡住不动怎么解决”,文...
今天小编给大家分享一下如何检测nodejs有没有安装成功的相关...