localhost:3000 / traceur SystemJS与AngularFire

时间:2016-09-23 20:45:32

标签: systemjs angularfire2

我选择了getting started with Angular2 tutorial格式,只添加了angularfire2部分。

我使用angularfire2 docs page

上的步骤安装了firebase和angularfire2

以下是我的systemjs.config.js

/**
 * System configuration for Angular 2 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',
      'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',
      'angularfire2':               'npm:angularfire2'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular2-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      },
      angularfire2: {
        main: 'index.js',
        defautExtension: 'js'
      }
    }
  });
})(this);

然后我就像这样导入它:

import { AngularFireModule } from 'angularfire2';

然后我不断收到此错误:

enter image description here

任何暗示发生了什么?

2 个答案:

答案 0 :(得分:3)

你的配置将angularfire2映射到node_modules/angularfire2/index.js,编写的是es6,因此SystemJS尝试使用traceur编译它,但找不到它。

简单的解决方法是配置它,以便在angular2/bundles/angularFire2.umd.js而非index.js中加载捆绑包。

angularfire2

中的packages
  angularfire2: {
    main: 'index.js'

需要更改为

  angularfire2: {
    main: 'bundles/angularFire2.umd.js'

此外,angularFire依赖于Firebase,因此,正如@Jonathon Oates在回答中所说,您还需要为Firebase提供配置。

答案 1 :(得分:3)

谢谢@artem - 我遇到了同样的问题!

您可能还需要在map中引用Firebase,例如

'firebase': 'npm:firebase'

将Firebase添加到您的packages,例如

  'angularfire2': {
    main: './bundles/angularFire2.umd.js',
    defaultExtension: 'js'
  },
  'firebase': {
    main: './firebase.js',
    defaultExtension: 'js'
  }

否则,您可能会看到Firebase发生新的404错误。