这是函数(从helloWorld
函数命令中获得的相同的firebase init
示例)。
import { onRequest } from 'firebase-functions/v2/https';
export const helloWorld = onRequest((req, res) => {
res.send('Hello from Firebase v2!');
});
在尝试部署它时,我会得到以下错误:
错误: helloWorld v2函数名只能包含小写字母、数字、连字符,长度不超过62个字符。
鉴于这一限制,我想将其命名为hello-world
。
但是如何在JS中导出hello-world
变量名呢?
更新
我刚试过:
exports['hello-world'] = onRequest((req, res) => {
res.send('Hello from Firebase v2!');
});
现在我发现了一个错误:
错误:函数名"hello-world“无效。函数名不能包含破折号。
那我能给它起什么名字?
我不想把它命名为helloworld
(全小写)。
他们接受连字符但不接受破折号?太让人困惑了。
更新2:
我从下面的答案中尝试了这个方法,但似乎行不通。
发布于 2022-09-26 06:16:55
有多种方法可以用破折号导出函数。下面是导出函数的一种方法:
import { onRequest } from 'firebase-functions/v2/https';
const helloWorld = onRequest((req, res) => {
res.send('Hello from Firebase v2!');
});
export { helloWorld as "hello-world" }
注意:如果您正在使用Visual或其他IDE,则可以将其识别为无效,但部署它将不会造成问题。见下面的样本:
您还可以检查此文档是否有其他导出声明方式。
https://stackoverflow.com/questions/73849507
复制相似问题