Firebase-Admin,将其导入以响应应用程序引发模块未找到错误 [英] Firebase-Admin, importing it to react application throws Module not found error

查看:71
本文介绍了Firebase-Admin,将其导入以响应应用程序引发模块未找到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用firebase admin的简单React应用程序.

I'm developming simple React application which uses firebase admin.

我通过使用创建React应用生成了React应用.

I have generated react application by using create react app.

然后我使用以下npm命令安装了firebase-admin:

Then I have installed firebase-admin by using this npm command:

npm install firebase-admin --save

在我的index.js中,我已添加以下导入:

In my index.js I have added this import:

 import React from 'react';
 import ReactDOM from 'react-dom';
 import App from './App';
 import registerServiceWorker from './registerServiceWorker';

 import * as admin from 'firebase-admin'

 ReactDOM.render(<App />, document.getElementById('root'));
 registerServiceWorker();

当我使用npm start命令启动并打开页面时,出现此错误:

When I launch with npm start command and open my page I get this error:

 Module not found: Can't resolve 'dns' in 'D:\path\to\my\project\node_modules\firebase-admin\node_modules\isemail\lib'

为什么会这样?我错过了什么吗?

Why this is happening? Did I miss something?

推荐答案

Admin SDK不能在客户端环境中使用.包括网络浏览器. Admin SDK可以并且应该仅在Firebase应用程序开发人员拥有或管理的特权服务器环境中使用.您应该在React应用中使用 Firebase Web SDK .

Admin SDKs cannot be used in client-side environments. That includes web browsers. Admin SDKs can and should only be used in privileged server environments owned or managed by the developers of a Firebase app. You should use the Firebase web SDK in your React app.

这篇关于Firebase-Admin,将其导入以响应应用程序引发模块未找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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