Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么export const helloWorld在firebase部署和导出中出现错误。helloWorld没有?_Javascript_Firebase_Google Cloud Functions - Fatal编程技术网

Javascript 为什么export const helloWorld在firebase部署和导出中出现错误。helloWorld没有?

Javascript 为什么export const helloWorld在firebase部署和导出中出现错误。helloWorld没有?,javascript,firebase,google-cloud-functions,Javascript,Firebase,Google Cloud Functions,在一个使用Expo的React原生项目中,我试图使用导出部署以下云功能: 注意:我在index.js中使用Javascript export const helloWorld=functions.https.onRequest((请求,响应)=>{ 回复。发送(“来自Firebase的你好!”); }); 但我有一个错误: Error: Error occurred while parsing your function triggers. /Users.../functions/index

在一个使用Expo的React原生项目中,我试图使用
导出
部署以下云功能:

注意:我在
index.js
中使用Javascript

export const helloWorld=functions.https.onRequest((请求,响应)=>{
回复。发送(“来自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((请求,响应)=>{
回复。发送(“来自Firebase的你好!”);
});
有人能解释为什么会这样吗

谢谢

将其更改为:

const helloWorld = functions.https.onRequest((request, response) => {
 response.send("Hello from Firebase!");
});

module.exports = helloWorld
直接出口使出口成为出口之一。ie:指的是出口


Module.exports在引用的位置直接分配导出。

Hey@DougStevenson感谢您的回复。如我所见:“NodeJS使用CommonJS模块语法(Module.exports),而不是ES6模块语法(export关键字)”。但是为什么在你的教程中它与TypeScript一起工作呢?当代码在lib文件夹中将其编译为Javascript时,是否会在commonjs和babel中传输?TypeScript总是传输的,您必须选择它使用的模块系统。Firebase在创建项目时,会在tsconfig.json中为您选择正确的项目。通过查看lib下的javascript代码,您可以看到它生成了什么。我会听从你的建议!实际上,在使用
module.exports=…
时,我在部署函数时遇到了问题。请查看我的评论