在一个使用Expo的React Native项目中,我试图使用export
:部署以下云功能
注意:我在index.js
中使用Javascript。
export const helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
但我得到了这个错误:
Error: Error occurred while parsing your function triggers.
/Users.../functions/index.js:5
export const helloWorld = functions.https.onRequest((request, response) => {
^^^^^^
SyntaxError: Unexpected token export
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
然后我用了exports.helloWorld...
,效果很好!
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
有人能解释为什么会发生这种事吗?
感谢
将其更改为:
const helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
module.exports = helloWorld
直接出口使出口成为出口之一。出口转介
Module.exports将导出直接分配到引用的位置。