2017-02-03 6 views
2

typescript transpilerが動作していません。私の@角型コンポーネントがロードされていません。私はこのエラーを取得しています: ZoneAwareError:Angular2とSystemJsとtypescript transpilerが動作しない

"Error: core_1.Component is not a function 
    Evaluating http://127.0.0.1:64223/app/app.component.ts 
    Evaluating http://127.0.0.1:64223/app/app.module.ts 
    Evaluating http://127.0.0.1:64223/app/main.ts 
    Loading app 
    at LoaderError__Check_error_message_for_loader_stack (http://127.0.0.1:64223/node_modules/systemjs/dist/system.src.js:78:11) [<root>] 
    at http://127.0.0.1:64223/node_modules/systemjs/dist/system.src.js:281:11 [<root>] 
    at Zone.run (http://127.0.0.1:64223/node_modules/zone.js/dist/zone.js:113:43) [<root> => <root>] 
    at http://127.0.0.1:64223/node_modules/zone.js/dist/zone.js:535:57 [<root>] 
    at Zone.runTask (http://127.0.0.1:64223/node_modules/zone.js/dist/zone.js:151:47) [<root> => <root>] 
    at drainMicroTaskQueue (http://127.0.0.1:64223/node_modules/zone.js/dist/zone.js:433:35) [<root>]" 

私はtranspiler生産が得意is'tことを知っているが、私はDEVのENVでそれを使用しています。 だから私の構成は次です:

のTSconfig

{ 
    "disableCompileOnSave": true, 
    "compileOnSave": false, 
    "compilerOptions" : { 
    "target" : "ES5", 
    "module" : "commonjs", 
    "experimentalDecorators" : true, 
    "noImplicitAny" : true 
    } 
} 

systemjs

System.config({ 
    transpiler: 'ts', 
    typescriptOptions: { 
     module: "system", 
     target: "es2015", 
     emitDecoratorMetadata: true, 
     experimentalDecorators: true 
    }, 

    map: { 
     "ts": "/node_modules/plugin-typescript/lib", 
     "typescript": "/node_modules/typescript", 

     'rxjs': 'node_modules/rxjs', 
     '@angular': 'node_modules/@angular', 
     '@angular/common': 'node_modules/@angular/common/bundles', 
     '@angular/core': 'node_modules/@angular/core/bundles', 
     '@angular/compiler': 'node_modules/@angular/compiler/bundles', 
     '@angular/platform-browser': 'node_modules/@angular/platform-browser/bundles', 
     '@angular/platform-browser-dynamic': 'node_modules/@angular/platform-browser-dynamic/bundles' 
    }, 

    packages: { 
    "ts": { 
     "main": "plugin.js" 
    }, 
    "typescript": { 
     "main": "/lib/typescript.js", 
     "meta": { 
     "/lib/typescript.js": { 
      "exports": "ts" 
     } 
     } 
    }, 
    'app'        : {main: 'main', defaultExtension: 'ts'}, 
    'rxjs'        : {main: 'Rx'}, 
     '@angular/common': { main: 'common.umd.js'}, 
     '@angular/core': { main: 'core.umd.js'}, 
     '@angular/compiler': { main: 'compiler.umd.js'}, 
     '@angular/platform-browser': { main: 'platform-browser.umd.js'}, 
     '@angular/platform-browser-dynamic': { main: 'platform-browser-dynamic.umd.js'}, 
    } 
}); 

index.htmlを

<!DOCTYPE html> 
<html> 
<head> 
    <title>Angular seed project</title> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 

    <script src="node_modules/typescript/lib/typescript.js"></script> 
    <script src="node_modules/core-js/client/shim.min.js"></script> 
    <script src="node_modules/zone.js/dist/zone.js"></script> 
    <script src="node_modules/systemjs/dist/system.src.js"></script> 
    <script src="system.config.js"></script> 
    <script> 

     System.import('app').catch(function(err){ console.error(err); }); 
    </script> 
</head> 

<body> 
<app>Loading...</app> 
</body> 
</html> 

package.json

{ 
    "name": "angular2", 
    "description": "", 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1", 
    "start": "live-server" 
    }, 
    "private": true, 
    "dependencies": { 
    "@angular/common": "^2.4.5", 
    "@angular/compiler": "^2.4.5", 
    "@angular/core": "^2.4.5", 
    "@angular/forms": "^2.4.5", 
    "@angular/http": "^2.4.5", 
    "@angular/platform-browser": "^2.4.5", 
    "@angular/platform-browser-dynamic": "^2.4.5", 
    "@angular/router": "^3.4.5", 
    "core-js": "^2.4.1", 
    "plugin-typescript": "^6.0.4", 
    "rxjs": "^5.1.0", 
    "systemjs": "^0.20.5", 
    "zone.js": "^0.7.6" 
    }, 
    "devDependencies": { 
    "live-server": "^1.2.0", 
    "typescript": "2.0.0" 
    } 
} 

、私のコンポーネントおよびモジュール:

アプリ/

import { Component } from '@angular/core'; 
console.log('@angular/core'); 
@Component({ 
    selector: 'app', 
    template: ` 
    <h1>{{title}}</h1> 
    <h2>My favorite hero is: {{myHero}}</h2> 
    ` 
}) 
export class AppComponent { 
    title = 'Tour of Heroes'; 
    myHero = 'Windstorm'; 
} 

アプリ/ app.module.ts

をapp.component.ts
import { NgModule } from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { AppComponent } from './app.component'; 

@NgModule({ 
    imports: [BrowserModule], 
    declarations: [AppComponent], 
    bootstrap: [AppComponent] 
}) 

export class AppModule { } 

アプリ/ main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 

import { AppModule } from './app.module'; 

platformBrowserDynamic().bootstrapModule(AppModule); 

おそらくsystem.js設定がおかしいです。私は昨夜これで苦労して助けを求めています。

+0

私はangle-cliを使用することをお勧めします。これはすべての設定を処理し、素晴らしいツールです。 – shammelburg

+0

@shammelburgどのような例ですか? – user4785882

+0

https://github.com/angular/angular-cli – shammelburg

答えて

0

今日も同じエラーが発生していて、動作するものが見つかりました。 私はこの

"compilerOptions": { 
"emitDecoratorMetadata": true, 
"experimentalDecorators": true, 
"module": "system", 
"moduleResolution": "node", 
"noImplicitAny": false, 
"noEmitOnError": false, 
"removeComments": false, 
"sourceMap": true, 
"target": "es5" 

等のTSconfig}、 "除外" を有していた:[ "node_modules"、 "wwwrootの"] }

Iは、角クイックスタートからのサンプルと比較し彼らが使用していたことに気付きました。コモンズ

"compilerOptions": { 
"emitDecoratorMetadata": true, 
"experimentalDecorators": true, 
"module": "commonjs", 
"moduleResolution": "node", 
"noImplicitAny": false, 
"noEmitOnError": false, 
"removeComments": false, 
"sourceMap": true, 
"target": "es5" 

}、 "除外":[ "node_modules"、 "wwwrootの" ] }

TSファイルを再コンパイルし、それが働きました。

0

公式の角度2のプロジェクトジェネレータを使用していますか?角張った角膜は今Webpackを使用しています(https://github.com/angular/angular-cli)。WebPACKの施設角度-CLI pussuiコンポーネントジェネレータ、サービスなど、社外

0

私はこの同じ問題を抱えていました。システムのバージョンをダウングレードしてみてください。私は0.20.12から0.19.40に私の変更し、アプリが突然動作し始めた。提案はhereからのものです。 tsconfigには"module": "system"があることに注意してください。もちろん、systemjsのバージョン文字列からキャレットを削除する必要があります。

関連する問題