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

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

问题描述

  1. 我使用的是来自 angular.io 的最新 (4.x.x) angular quickstart.
  2. 我想导入 firebaseangularfire2.

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

I imported the libraries in systemjs.config.js as :

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'
    },
}

错误屏幕上限

更新

我只想强调这个错误

无法加载转译器来转译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".模块.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 开发人员不断更改他们的设置,这里是当前的分步说明,如何使用 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.

从克隆官方quickstart repo开始

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

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.npm i angularfire2 似乎没有安装预捆绑的 angularfire 代码,因此您必须自己捆绑以进行生产.

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天全站免登陆