Firebase功能不起作用-无法模拟应用

人气:372 发布:2022-10-16 标签: firebase google-cloud-functions

问题描述

当我尝试提供Firebase云功能时,会收到此消息.

When I try to serve my firebase cloud functions, I get this message.

我的firebase.json文件在这里

My firebase.json file is here

{
  "hosting": {
    "public": "public",
    "rewrites":[{
        "source":"/hello",
        "function":"app"
    }]
  }
}

函数文件夹中的index.js文件

The index.js file inside function folder

const functions = require('firebase-functions');
const express = require('express');

const app = express();


app.get('/hello', (request, response)=>{
        response.send("Hello Working");
});

exports.app = functions.https.onRequest(app);

这是调试日志,显示了我遇到的错误.

And here is the debug log that shows the error I am getting.

Error: ENOENT: no such file or directory, chmod 'C:\Program Files\Java\jre1.8.0_171\bin;C:\Program Files\Java\jdk1.8.0_171\bin;C:\Users\iambe\AppData\Local\Temp;\tmp-47763kzGi6NyBhNP.zip'
    at Error (native)
    at Object.fs.chmodSync (fs.js:1169:18)
    at Object.writeFileTo (C:\Users\iambe\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\adm-zip\util\utils.js:111:20)
    at Object.writeZip (C:\Users\iambe\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\adm-zip\adm-zip.js:534:20)
    at client.generateUploadUrl.then.then (C:\Users\iambe\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\@google-cloud\functions-emulator\src\cli\controller.js:168:13)
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)
[warn] !  functions: Failed to emulate app
[info] i  functions: No HTTPS functions found. Use firebase functions:shell if you would like to emulate other types of functions.

是否有人遇到类似问题并得到解决?我尝试搜索到处都无济于事.

If anyone faced the similar issue and solved? I tried searching everywhere nothing helped so far.

推荐答案

最后,我找到了解决方案.这里的问题不是节点版本,而是临时目录位置. 在错误消息中,我们可以看到它说没有这样的文件或目录,然后我们可以看到它正在检查文件的路径.

Finally I find the solution. The problem here is not with the node version but with the temp directory location. In the error message we can see that it is saying that no such file or directory and after this we can see the path where it is checking for the file.

C:\Program Files\Java\jdk1.8.0_171\bin;C:\Users\iambe\AppData\Local\Temp

所以这里的问题是我们也为nodejs设置了一个临时目录.但是由于系统的temp目录的设置,出现了一些问题并且节点感到困惑.它不是在查看nodejs临时目录,而是在Windows temp目录.

So the problem here is we have a temp directory configuration for nodejs as well. But there is some issue and node is getting confused because of the settings of temp directory of the system. And it is not looking at nodejs temp directory but it is looking at windows temp directory.

这是问题的解释.现在让我告诉您解决方案.我所做的是从环境变量中删除了TEMP变量.

This is the explanation of the problem. Now let me tell you the solution. What I did is I removed the TEMP variable from the environment variables.

您已完成.希望这会有所帮助.

And you are done. Hope this will help.

但是我不确定为什么会这样,因为在某些具有此temp目录的计算机中也没有问题.但是在某些计算机中,我们会遇到此问题.如果有人有确切原因,请告诉我.

But I am not sure why this is happening because in some computers with this temp directory as well no problem. But in some computers we have this problem. If anyone having the exact reason, let me know.

951