Firebaseに機能をデプロイしようとしていますが、デプロイ中にエラーが発生します
エラー:関数は適切にデプロイされませんでした。
非同期機能とリンクできますか?
実際の動作関数はエラーを伴ってデプロイされ、cliは次のメッセージを表示します:
================コンソールログ================
> 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 = '[email protected]'
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
}
2019年9月:
npm install --save firebase-admin
npm install --save firebase-functions
"engines": { "node": "10" }
を/functions/package.jsonに追加します...
"dependencies": {
"firebase-admin": "^8.5.0",
"firebase-functions": "^3.2.0"
},
"devDependencies": {
"tslint": "~5.19.0",
"TypeScript": "~3.6.2"
},
"engines": {
"node": "10"
}
...
2018年8月:
Cloud FunctionsがNode 8(8.11.1)をサポートするようになりました。チェックアウト このブログ投稿 。
Node 8へのアップグレード
このブログ投稿 で提案されているように、以下の手順に従ってNode 8:
npm install --save firebase-functions@latest
経由でfirebase-functionsバージョンをアップグレードしますnpm update -g firebase-tools
経由でfirebase-toolsをアップグレードします"engines": { "node": "8" }
を/functions/package.json
に追加します