我只是按照谷歌云功能教程上的分步过程进行操作,有人知道如何解决这个问题吗? 还是问题的原因?



我只按照谷歌火力基地上的分步教程进行操作 这是链接:

https://firebase.google.com/docs/functions/get-started?authuser=0

然后我在cmd上得到这些

Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:9
exports.addMessage = functions.https.onRequest(async(req, res) => {
^
SyntaxError: Unexpected token (
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at getUserFunction (/var/tmp/worker/worker.js:439:24)

Functions deploy had errors with the following functions:
addMessage

这些是教程中的代码。

// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp();
// Take the text parameter passed to this HTTP endpoint and insert it into the
// Realtime Database under the path /messages/:pushId/original
exports.addMessage = functions.https.onRequest(async(req, res) => {
// Grab the text parameter.
const original = req.query.text;
// Push the new message into the Realtime Database using the Firebase Admin SDK.`enter code here`
const snapshot = await admin.database().ref('/messages').push({original: 
original});
// Redirect with 303 SEE OTHER to the URL of the pushed object in the 
Firebase console.
res.redirect(303, snapshot.ref.toString());
});

查看您发布的代码与示例中的代码的比较,我认为问题是:

您的代码:

exports.addMessage = functions.https.onRequest(async(req, res) => {

示例代码:

exports.addMessage = functions.https.onRequest(async (req, res) => {

请注意,在您的代码中,async之后没有"空格"字符。 异步是将函数标记为异步的函数的限定符。 有关异步的详细信息,请参阅此处。

空间的省略会改变语义。 如果我不得不猜测,运行时现在将寻找一个名为async函数。 请更改您的代码以包含空格。

最新更新