AngularFire2 初始化应用程序出错 [英] AngularFire2 initializing app gives error

查看:29
本文介绍了AngularFire2 初始化应用程序出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 Angular2 应用程序中初始化 AngularFire2,但出现以下错误.

 ./src/app/firebase/index.ts 中的错误模块构建失败:错误:/Users/jaruesink/Documents/Projects/buckets/src/app/firebase/index.ts(16,17):导出函数的返回类型具有或正在使用来自外部模块的名称ModuleWithProviders"/用户/jaruesink/Documents/Projects/buckets/node_modules/@angular/core/src/metadata/ng_module"但不能命名.)在 _checkDiagnostics (/Users/jaruesink/Documents/Projects/buckets/node_modules/@ngtools/webpack/src/loader.js:115:15)在/Users/jaruesink/Documents/Projects/buckets/node_modules/@ngtools/webpack/src/loader.js:140:17@ ./src/app/app.module.ts 15:0-48@ ./src/app/index.ts@ ./src/main.ts@多主

这是我尝试在 NgModule 中导入为 initializeFirebase() 的 Firebase 模块.

import { AngularFireModule, AuthProviders, AuthMethods } from 'angularfire2';导出 const firebaseConfig = {FIREBASE 的东西在这里};导出 const firebaseAuthConfig = {提供者:AuthProviders.Facebook,方法:AuthMethods.Redirect}导出函数 initializeFirebase() {返回 AngularFireModule.initializeApp(firebaseConfig, firebaseAuthConfig);}

有人可以帮助解释我做错了什么,或者如果发生了其他事情,我有什么方法可以解决它吗?

谢谢!

解决方案

放在外部文件中不起作用的原因与这个功能有关:

导出函数 initializeFirebase() {返回 AngularFireModule.initializeApp(firebaseConfig, firebaseAuthConfig);}

声明未指定返回类型,因此推断为 ModuleWithProviders - initializeApp 的返回类型(以及错误中提到的类型).

为了解决这个问题,你可以指定返回类型,这也意味着你需要添加一个导入:

import { ModuleWithProviders } from '@angular/core';...导出函数 initializeFirebase(): ModuleWithProviders {返回 AngularFireModule.initializeApp(firebaseConfig, firebaseAuthConfig);}

有关详细信息,请参阅此 GitHub 问题评论

I am trying to initialize AngularFire2 in my Angular2 application, but I am getting the following error.

ERROR in ./src/app/firebase/index.ts
Module build failed: Error: /Users/jaruesink/Documents/Projects/buckets/src/app/firebase/index.ts (16,17): Return type of exported function has or is using name 'ModuleWithProviders' from external module "/Users/jaruesink/Documents/Projects/buckets/node_modules/@angular/core/src/metadata/ng_module" but cannot be named.)
    at _checkDiagnostics (/Users/jaruesink/Documents/Projects/buckets/node_modules/@ngtools/webpack/src/loader.js:115:15)
    at /Users/jaruesink/Documents/Projects/buckets/node_modules/@ngtools/webpack/src/loader.js:140:17
 @ ./src/app/app.module.ts 15:0-48
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi main

Here is my Firebase module that I am trying to import as initializeFirebase() in my NgModule.

import { AngularFireModule, AuthProviders, AuthMethods } from 'angularfire2';

export const firebaseConfig = {
  FIREBASE STUFF GOES HERE
};

export const firebaseAuthConfig = {
  provider: AuthProviders.Facebook,
  method: AuthMethods.Redirect
}

export function initializeFirebase() {
  return AngularFireModule.initializeApp(firebaseConfig, firebaseAuthConfig);
}

Can someone help explain what I am doing wrong, or if something else is going on, is there a way I can work around it?

Thanks!

解决方案

The reason it does not work when placed in the external file has to do with this function:

export function initializeFirebase() {
  return AngularFireModule.initializeApp(firebaseConfig, firebaseAuthConfig);
}

The declaration does not specify a return type, so it's inferred to be ModuleWithProviders - the return type of initializeApp (and the type that's mentioned in the error).

To solve the problem, you can specify the return type, which will also mean you need to add an import:

import { ModuleWithProviders } from '@angular/core';
...
export function initializeFirebase(): ModuleWithProviders {
  return AngularFireModule.initializeApp(firebaseConfig, firebaseAuthConfig);
}

For more information, see this GitHub issue comment

这篇关于AngularFire2 初始化应用程序出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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