在版本 5.7.0 中找不到模块 'firebase/app'

Cannot find module 'firebase/app' in version 5.7.0

我正在尝试构建一个要部署在 Firebase 上的 angular 项目,但由于以下原因,我无法 运行 我的 npm run build 甚至 npm start 命令以下错误。

ERROR in node_modules/@angular/fire/database/interfaces.d.ts(2,26): error TS2307: Cannot find module 'firebase/app'. node_modules/@angular/fire/firebase.app.module.d.ts(2,79): error TS2307: Cannot find module 'firebase/app'.

我已经完成了过去的问题,并清除了我的 node_modules 文件夹和 package-lock.json 文件,并重新安装了所有依赖项。我仍然不断收到此错误。

这是我在我的应用程序中使用的内容:

"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"angularfire2": "^5.1.1",
"bootstrap": "^4.1.3",
"core-js": "^2.4.1",
"firebase": "^5.7.0",
"jquery": "^3.3.1",
"particles.js": "^2.0.0",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"

有人可以帮我解决这个问题吗?先感谢您。

干杯!

也许尝试使用 angularFire2,它似乎是 angular firebase 库 ;-)

angularfire2 @ github

angularfire2 @ npm

这个firebase issue好像是一样的

另外这个 angularFire2 Stackblitz 演示对我有用。

编辑:

最后但同样重要的是,您可以更新 angular 版本(尝试使用 angular6 或 7)。

引自 firebase 问题:

Also I noticed you are on Angular 5. Would you be able to upgrade to angular6 or 7 and use the new cli to see if the problem persist? AngularFire project doesn't seem to have this problem and they are on angular6: https://github.com/angular/angularfire2

我根据@zerocewl 的建议将 angularFire2 更改为@angular/fire。

不仅在 npm install,而且在 app.module.ts。安装 npm-check-updates 和 然后我使用 ncu -unpm install 将所有内容更新到最新版本。

通过降级到版本 3.1.6 解决了打字稿问题:

ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.2 was found instead.

然后成功了!