【发布时间】:2021-10-21 14:12:47
【问题描述】:
我正在尝试使用React 在Firebase 上建立一个简单的项目。
为此,我遵循本教程:
Getting Started with React and Firebase - 1
我跑完之后:
npm install firebase --save
我可以在 package.json 依赖项中看到(如我所料)这一行:
"firebase": "^9.1.3",
然而,当我想编译我的代码时,看起来像这样:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import * as firebase from 'firebase';
const firebaseConfig = {
apiKey: ".....",
authDomain: "myapp.firebaseapp.com",
projectId: "myapp",
storageBucket: "myapp.appspot.com",
messagingSenderId: "12456...",
appId: "1:1.....:web:c......."
};
const app = initializeApp(firebaseConfig);
我收到此错误:
Failed to compile.
./src/index.js
Module not found: Can't resolve 'firebase' in '/Users/me/Documents/.../myapp/src'
我的本意是按照教程进行操作,但结果出错了。 是不是文件过时了?还是我遗漏了一些重要的细节?
希望有人能指出问题和解决方法。
更多补充信息:
当我在项目目录中运行这个命令时:
find node_modules -name firebase*
我得到一个相当长的结果,其中包含以下行:
node_modules/firebase/....
以及类似的行:
node_modules/@firebase/....
然后尝试:
find node_modules -name firebase.js
还有:
find . -name firebase.js
这两个命令都不返回任何内容。
【问题讨论】: