Angular TypeScript错误:找不到traceur 404 [英] Angular TypeScript Error : traceur 404 not found

查看:60
本文介绍了Angular TypeScript错误:找不到traceur 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我正在使用angular.io中最新的(4.x.x)角度快速入门.
  2. 我要导入 firebase angularfire2 .
  1. I am using the latest (4.x.x) angular quickstart from angular.io.
  2. I want to import firebase and angularfire2.

我将 systemjs.config.js 中的库导入为:

map: {
    ...
    'firebase': 'npm:firebase',
    'angularfire2': 'npm:angularfire2/bundles/angularfire2.umd.js',
    'angularfire2/auth': 'npm:angularfire2/auth',
    'angularfire2/database': 'npm:angularfire2/database',
    ...
},
packages: {
    app: {
        defaultExtension: 'js',
        meta: {
            './*.js': {
                loader: 'systemjs-angular-loader.js'
            }
        }
    },
    'firebase':{
        main: './firebase.js',
        defaultExtension: 'js'
    },
    'angularfire2/database':{
        main: './database.js',
        defaultExtension: 'js'
    },
    'angularfire2/auth':{
        main: './auth.js',
        defaultExtension: 'js'
    },
}

错误屏幕提示

更新

我只想强调这个错误

无法加载Transpiler进行编译 http://localhost:3000/node_modules/angularfire2/database/database.js 加载 http://localhost:3000/node_modules/angularfire2/database/database.js 作为 http://localhost:3000/app/app中的"angularfire2/database". module.js

Unable to load transpiler to transpile http://localhost:3000/node_modules/angularfire2/database/database.js Error loading http://localhost:3000/node_modules/angularfire2/database/database.js as "angularfire2/database" from http://localhost:3000/app/app.module.js

推荐答案

好吧,由于此处的角度开发人员不断更改其设置,因此它们是当前逐步说明,说明如何使用angular 4快速入门示例加载angularfire2数据库模块.

Ok, since angular developers keep changing their setup here are current step-by-step instructions how to load angularfire2 database module with angular 4 quickstart example.

从克隆官方快速入门仓库开始

start with cloning official quickstart repo

git clone https://github.com/angular/quickstart.git quickstart

安装其他依赖项

npm i --save-dev angularfire2 firebase promise-polyfill plugin-typescript@6.0.4

将tsconfig.json更改为使用"module": "system"

change tsconfig.json to use "module": "system"

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es2015", "dom" ],
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  }
}

向systemjs.config.js添加必要的内容

add necessary stuff to systemjs.config.js

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    transpiler: 'ts',
    typescriptOptions: {
      tsconfig: true
    },
    meta: {
      'typescript': {
        "exports": "ts"
      }
    },
    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',

      'angularfire2': 'npm:angularfire2',
      'ts':                         'npm:plugin-typescript',
      'typescript':                 'npm:typescript/lib/typescript.js',
      'firebase':                   'npm:firebase',
      'promise-polyfill':           'npm:promise-polyfill/promise.js',
      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.ts',
        defaultExtension: 'ts',
        meta: {
          './*.ts': {
            loader: 'systemjs-angular-loader.js'
          }
        }
      },
      rxjs: {
        defaultExtension: 'js'
      },
      angularfire2: {
        main: 'angularfire2.js',
        defaultExtension: 'js'
      },
      firebase: {
        defaultExtension: 'js'
      },
      ts: {
        main: 'lib/plugin.js',
        defaultExtension: 'js'
      }

    }
  });
})(this);

AngularFireModuleAngularFireDatabaseModule添加到app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AppComponent }   from './app.component';

@NgModule({
  imports:      [
    BrowserModule,
    AngularFireModule.initializeApp({
// NOTE: USE YOUR OWN API KEY
      apiKey: "AIzaSyDFbuKX0UeXje-PRAvwIymYo2jk-uGqMa4",
      authDomain: "test-bc800.firebaseapp.com",
      databaseURL: "https://test-bc800.firebaseio.com",
      storageBucket: ""
    }),
    AngularFireDatabaseModule
  ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})

export class AppModule { }

app.component.ts中使用db

import { Component } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Subject } from 'rxjs/Subject';

@Component({
  selector: 'my-app',
  template: '<h1>Angularfire2 example app</h1>'
})
export class AppComponent {


  constructor(db: AngularFireDatabase) {
    // use db here
  }

}

请注意,尽管此示例可以正常工作,但它会在浏览器中将angularfire源代码从es6编译为javascript.似乎预捆绑的angularfire代码未随npm i angularfire2一起安装,因此您必须自己将其捆绑以进行生产.

Note that while this example works, it compiles angularfire source code from es6 to javascript in the browser. It seems like pre-bundled angularfire code was not installed with npm i angularfire2, so you will have to bundle it yourself for production.

这篇关于Angular TypeScript错误:找不到traceur 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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