简体   繁体   English

Angularfire2在Angular2中导致SystemJS错误

[英]Angularfire2 causing SystemJS errors in Angular2

I'm trying to get my Firebase database connected to my Angular 2 app which I've done a few times in the past without any problems. 我正在尝试将Firebase数据库连接到Angular 2应用程序,该应用程序过去已经完成了几次,没有任何问题。 For some reason I'm getting this error 由于某种原因,我收到此错误

Error: Can't resolve all parameters for AppService: (?).
        at Error (native)
        at syntaxError (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:1513:34)
        at CompileMetadataResolver._getDependenciesMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14790:35)
        at CompileMetadataResolver._getTypeMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14658:26)
        at CompileMetadataResolver._getInjectableMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14644:21)
        at CompileMetadataResolver.getProviderMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14933:40)
        at eval (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14863:49)
        at Array.forEach (native)
        at CompileMetadataResolver._getProvidersMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14824:19)
        at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14255:30)
    Evaluating http://localhost:3000/main.js
    Error loading http://localhost:3000/main.js
        at Error (native)
        at syntaxError (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:1513:34)
        at CompileMetadataResolver._getDependenciesMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14790:35)
        at CompileMetadataResolver._getTypeMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14658:26)
        at CompileMetadataResolver._getInjectableMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14644:21)
        at CompileMetadataResolver.getProviderMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14933:40)
        at eval (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14863:49)
        at Array.forEach (native)
        at CompileMetadataResolver._getProvidersMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14824:19)
        at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14255:30)
    Evaluating http://localhost:3000/main.js
    Error loading http://localhost:3000/main.js

At first the app wouldn't work at all then I came across this https://github.com/angular/angularfire2/pull/1041 起初该应用程序根本无法工作,然后我遇到了这个https://github.com/angular/angularfire2/pull/1041

The fix they gave had the extensions all.umd.js for the angularfire parts while the files in my angularfire folder only have umd.js versions so I made the modification to suit the files I had and now I'm stuck at this current error. 他们提供的修复程序对angularfire部件具有扩展名all.umd.js ,而我的angularfire文件夹中的文件仅具有umd.js版本,因此我进行了修改以适合所拥有的文件,现在我陷入了当前错误。

Here's what my files look like 这是我的文件的样子

package.json package.json

{
  "name": "optiq_vision_splash_page",
  "version": "1.0.0",
  "description": "QuickStart package.json from the documentation, supplemented with testing support",
  "scripts": {
    "build": "tsc -p src/",
    "build:watch": "tsc -p src/ -w",
    "build:e2e": "tsc -p e2e/",
    "serve": "lite-server -c=bs-config.json",
    "serve:e2e": "lite-server -c=bs-config.e2e.json",
    "prestart": "npm run build",
    "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
    "pree2e": "npm run build:e2e",
    "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
    "preprotractor": "webdriver-manager update",
    "protractor": "protractor protractor.config.js",
    "pretest": "npm run build",
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
    "pretest:once": "npm run build",
    "test:once": "karma start karma.conf.js --single-run",
    "lint": "tslint ./src/**/*.ts -t verbose"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@angular/common": "~4.0.0",
    "@angular/compiler": "~4.0.0",
    "@angular/core": "~4.0.0",
    "@angular/forms": "~4.0.0",
    "@angular/http": "~4.0.0",
    "@angular/platform-browser": "~4.0.0",
    "@angular/platform-browser-dynamic": "~4.0.0",
    "@angular/router": "~4.0.0",
    "@types/node": "^6.0.87",
    "angular-in-memory-web-api": "~0.3.0",
    "angularfire2": "^4.0.0-rc.1",
    "core-js": "^2.4.1",
    "firebase": "^4.2.0",
    "rxjs": "5.0.1",
    "systemjs": "0.19.40",
     "zone.js": "^0.8.4"
   },
  "devDependencies": {
    "concurrently": "^3.2.0",
    "lite-server": "^2.2.2",
    "typescript": "~2.1.0",
    "canonical-path": "0.0.2",
    "tslint": "^3.15.1",
    "lodash": "^4.16.4",
    "jasmine-core": "~2.4.1",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~4.0.14",
    "rimraf": "^2.5.4",
    "@types/node": "^6.0.46",
    "@types/jasmine": "2.5.36"
  },
  "repository": {}
}

systemjs.config.js systemjs.config.js

/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      'app': 'app',

      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
      'angularfire2' : 'npm:angularfire2/bundles/angularfire2.umd.js',
      'angularfire2/database' : 'npm:angularfire2/bundles/angularfire2.umd.js',
      'angularfire2/auth' : 'npm:angularfire2/bundles/angularfire2.umd.js',
      'firebase': 'npm:firebase/firebase.js',
      'firebase/app': 'npm:firebase/firebase.js',
      'firebase/database': 'npm:firebase/firebase.js',
      'firebase/auth': 'npm:firebase/firebase.js'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        defaultExtension: 'js',
        meta: {
          './*.js': {
            loader: 'systemjs-angular-loader.js'
          },
        firebase : {
            format: 'global',
            exports: 'firebase'
          }
        }
      },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);

app.module app.module

import { NgModule }             from '@angular/core';
import { BrowserModule }        from '@angular/platform-browser';
import { ReactiveFormsModule }  from '@angular/forms';
import { HttpModule }           from '@angular/http';
import { RouterModule, Routes } from '@angular/router';
import { AngularFireModule }    from 'angularfire2';

import { AppComponent }         from './app.component';
import { AppRoutingModule }     from './app-routing.module';

import { IntroComponent }       from './intro/intro.component';
import { LogoPage }             from './logo-design/logo.component';
import { AssetPage }            from './asset-design/asset.component';
import { CollateralPage }       from './collateral-design/collateral.component';



export const firebaseConfig ={
     apiKey: "blah",
     authDomain: "blah",
     databaseURL: "blah",
     projectId: "blah",
     storageBucket: "blah",
     messagingSenderId: "blah"
};

@NgModule({
    declarations: [
      AppComponent,
      IntroComponent,
      LogoPage, AssetPage, CollateralPage
    ],

    imports:      [
      BrowserModule,
      ReactiveFormsModule,
      HttpModule,
      AppRoutingModule,
      AngularFireModule.initializeApp(firebaseConfig)
    ],

    bootstrap:    [ AppComponent ]

})

export class AppModule { }

app.service 应用服务

import { Injectable,
         Inject }                   from '@angular/core';
import { Response }                 from '@angular/http';
import { Observable }               from 'rxjs/RX';

import { Link }                     from './links-interface';

import { AngularFire,
        FirebaseListObservable,
        FirebaseObjectObservable }  from 'angularfire2';

import 'rxjs/add/operator/map';



@Injectable()

export class AppService {
    SampleData: FirebaseObjectObservable<any>;

    constructor(private af: AngularFire){}

    getData(){
        this.SampleData = this.af.database.object('intro') as FirebaseObjectObservable<any>
        return this.SampleData;
    }


}

app.component 应用组件

import { Component,
         OnInit }                   from '@angular/core';

import { HttpModule }               from '@angular/http';

import { AngularFire,
        FirebaseListObservable,
        FirebaseObjectObservable }  from 'angularfire2';

import { AppService }               from './app.service';



@Component({

    moduleId: module.id,
    selector: 'my-app',
    templateUrl:'./app.component.html',
    styleUrls: ['./app.component.css'],
    providers: [ AppService ]
})



 export class AppComponent implements OnInit{

     Data: FirebaseObjectObservable<any>;

     constructor(private _data:AppService){}

     ngOnInit() {
        this._data.getData().subscribe(SampleData =>{
            this.Data = SampleData;
            console.log(this.Data);
        });
    }


 }

I noticed from looking at the system.config.js file where Angularfire2 is being incorporated all of them lead to the same file in the bundles folder. 我从查看合并了Angularfire2system.config.js文件中注意到,所有这些文件都导致bundles文件夹中的文件相同。 I noticed the same with Firebase . 我注意到Firebase I tried changing it directly to the auth , database etc. files but got more errors. 我尝试将其直接更改为authdatabase等文件,但出现了更多错误。

The reason I haven't upgraded to angular4 is because I have Windows Vista and can't update node. 我没有升级到angular4的原因是因为我有Windows Vista并且无法更新节点。 As of right now I'm running node 5.7 and npm 3.6 so I don't know if maybe that's causing a problem because I reently had to find and reinstall the most up to date version of Angular2 that works on my computer. 截至目前,我正在运行node 5.7npm 3.6所以我不知道这是否可能引起问题,因为我不得不重新寻找并重新安装在计算机上Angular2最新Angular2版本。 I didn't have this much trouble when I first started with Firebase so it's strange that I can't figure this one out. 刚开始使用Firebase时,我并没有那么多麻烦,所以很奇怪我无法解决这个问题。 All help is greatly appreciated. 非常感谢所有帮助。

You're on AngularFire2 version 4.0.0-rc.1 . 您正在使用AngularFire2版本4.0.0-rc.1 There was a large packaging rewrite for 4.0.0-rc.2 which fixed this issue for SystemJS. 4.0.0-rc.2进行了大包装重写,从而解决了SystemJS的此问题。

In the previous version resolving angularfire2/database and angularfire2/auth was done through a deep import. 在以前的版本中,通过深度导入来解决angularfire2/databaseangularfire2/auth This was fine if you were using webpack. 如果您使用的是webpack,那就很好。 However, SystemJS users require a UMD bundle. 但是,SystemJS用户需要UMD捆绑包。 Rather than just stuff each module in a mega UMD bundle, we changed the packaging to declare a package.json for each module that defined a UMD bundle. 我们不仅将大型UMD捆绑包中的每个模块塞满了,还更改了包装,为定义UMD捆绑包的每个模块声明了package.json。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM