【发布时间】:2021-04-25 21:07:47
【问题描述】:
我正在尝试安装 firebase 功能,以便在我的应用中实现支付 API。
然而,我正在阅读多个教程并阅读有关如何安装功能并使其正常工作的 firebase 手册。
我在终端卡住了......
lukasbimba@Lukass-iMac functions % firebase deploy --only functions
(node:51250) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created).
⚠ functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions@latest in your functions directory.
=== Deploying to 'shoppeer-e7270'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint /Users/lukasbimba/Desktop/Xcode Projects/ShopPeer/functions/functions
> eslint .
✔ functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
Error: HTTP Error: 404, Method not found.
Having trouble? Try firebase deploy --help
lukasbimba@Lukass-iMac functions %
index.js 文件
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
// // Create and Deploy Your First Cloud Functions
https://firebase.google.com/docs/functions/write-firebase-functions
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
// Take the text parameter passed to this HTTP endpoint and insert it into
// Firestore under the path /messages/:documentId/original
exports.addMessage = functions.https.onRequest(async (req, res) => {
// Grab the text parameter.
const original = req.query.text;
// Push the new message into Firestore using the Firebase Admin SDK.
const writeResult = await admin.firestore().collection('messages').add({original: original});
// Send back a message that we've successfully written the message
res.json({result: `Message with ID: ${writeResult.id} added.`});
});
// Listens for new messages added to /messages/:documentId/original and creates an
// uppercase version of the message to /messages/:documentId/uppercase
exports.makeUppercase = functions.firestore.document('/messages/{documentId}')
.onCreate((snap, context) => {
// Grab the current value of what was written to Firestore.
const original = snap.data().original;
// Access the parameter `{documentId}` with `context.params`
functions.logger.log('Uppercasing', context.params.documentId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to Firestore.
// Setting an 'uppercase' field in Firestore document returns a Promise.
return snap.ref.set({uppercase}, {merge: true});
});
【问题讨论】:
-
如果没有您的 Cloud Function 代码,将很难为您提供帮助。此外,您应该更新您的
firebase-functions软件包版本,如日志中所示。 -
我在哪里可以访问和显示我的云功能代码,我刚刚运行了更新并收到同样的错误
-
"我在哪里可以访问和显示我的云函数代码" => 这是您为定义云函数而编写的代码(默认情况下它位于
index.js文件中)。要显示它,只需编辑您的问题并粘贴即可。当然,如果你有几百行代码,在这里粘贴它是没有意义的!!在这种情况下,请提取/制作Minimal, Reproducible Example。 -
我已经添加了 index.js 文件
-
乍一看我没有发现任何问题。你能隔离造成问题的云函数吗?只需部署每个 Cloud Function,因为它是
index.js文件中唯一的一个,例如注释掉另外两个。
标签: firebase google-cloud-functions firebase-cli