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

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

问题描述

 在./中的错误

src / app / firebase / index.ts
模块构建失败:错误:/Users/jaruesink/Documents/Projects/buckets/src/app/firebase/index.ts(16,17):导出函数的返回类型已经或正在使用来自外部模块/ Users / jaruesink / Documents / Projects / buckets / node_modules / @ angular / core / src / metadata / ng_module的名称ModuleWithProviders,但无法命名。)
at _checkDiagnostics(/ $ users / jar /文件/项目/buckets/node_modules/@ngtools/webpack/src/loader.js:115: src / loader.js:140:17
@ ./src/app/app.module.ts 15:0-48
@ ./src/app/index.ts
@。 /src/main.ts
@ multi main

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

pre $ code>从'angularfire2'导入{AngularFireModule,AuthProviders,AuthMethods};

export const firebaseConfig = {
FIREBASE STUFF GOES HERE
};

export const firebaseAuthConfig = {
提供者:AuthProviders.Facebook,
方法:AuthMethods.Redirect
}

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





$ b有人可以帮我解释一下我做错了什么,有没有办法解决这个问题?



谢谢!

解决方案
$ p
$ b

  export函数initializeFirebase (){
返回AngularFireModule.initializeApp(firebaseConfig,firebaseAuthConfig);





声明没有指定返回类型,所以推断为 ModuleWithProviders - initializeApp 的返回类型(以及在错误中提到的类型)。

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

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

$ / code>

有关更多信息,请参阅此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天全站免登陆