详细的堆栈跟踪:错误:找不到模块"Users/myhUser/downloads/myFolder/my.Json/"; [英] Detailed stack trace: Error: Cannot find module "Users/myhUser/downloads/myFolder/my.Json/"

查看:74
本文介绍了详细的堆栈跟踪:错误:找不到模块"Users/myhUser/downloads/myFolder/my.Json/";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用node.js和terminal推送firebase函数.当我在Firebase中推送并查看日志时,

I am trying to push firebase functions with node.js and terminal. When I push and check my logs in firebase I am seeing,

详细的堆栈跟踪:错误:找不到模块'/Users/myUser/Downloads/myFolder/my.Json'

Detailed stack trace: Error: Cannot find module '/Users/myUser/Downloads/myFolder/my.Json'

您是否在package.json依赖项中列出了所有必需的模块?

Did you list all required modules in the package.json dependencies?

在我的node.js文件中,

In my node.js file, I have

var serviceAccount = require('/Users/myUser/Downloads/myFolder/my.Json');

 const admin = require('firebase-admin');
 admin.initializeApp({
 credential: admin.credential.cert(serviceAccount),
 databaseURL: "https://myproject.firebaseio.com"
 });

我试图在此处找到修复程序,但是不确定我应该在找什么.我没有正确初始化文件吗?我已经安装并更新了NPM,并且我的所有凭据都匹配.为什么会这样?

I have tried to find fixes on here but not sure what it is I am supposed to be looking for. Didn't I initialize the file correctly? I have NPM installed and updated and all of my credentials matched. Why is this happening?

推荐答案

在Cloud Functions上,不能使用带有require的脚本的绝对路径.您将需要使用相对路径,并确保文件位于functions文件夹中. Firebase CLI仅将文件部署在functions文件夹中.因此,如果您将my.Json复制到node.js旁边,则应该可以这样要求:

You can't use absolute paths to scripts with require on Cloud Functions. You will need to use a relative path, and make sure the file is in the functions folder. The Firebase CLI will only deploy the files in the functions folder. So, if you copy my.Json to sit next to node.js, you should be able to require it like this:

var serviceAccount = require('./my.Json');

这篇关于详细的堆栈跟踪:错误:找不到模块"Users/myhUser/downloads/myFolder/my.Json/";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆