2016-11-28 234 views
1

我試圖啓動一個項目Angular2 /打字稿/ ASP.Net核心 與NPM /咕嘟咕嘟/ SystemJSangular2用asp.net核心和systemjs安裝

但似乎所有的教程在那裏不UPTODATE或我錯過了一些東西...

當我嘗試 - >從{@ angular/core'導入{組件};; Visual Studio不再構建,並說它無法找到模塊'@ angular/core'。

這裏是我的configs文件:

NPM:

{ 
    "dependencies": { 
     "@angular/common": "2.1.2", 
     "@angular/compiler": "2.1.2", 
     "@angular/core": "2.1.2", 
     "@angular/forms": "2.1.2", 
     "@angular/http": "2.1.2", 
     "@angular/platform-browser": "2.1.2", 
     "@angular/platform-browser-dynamic": "2.1.2", 
     "@angular/router": "3.1.2", 
     "@angular/upgrade": "2.1.2", 
     "core-js": "^2.4.1", 
     "moment": "^2.14.1", 
     "ng2-bootstrap": "^1.0.24", 
     "reflect-metadata": "^0.1.3", 
     "rxjs": "5.0.0-beta.6", 
     "systemjs": "^0.19.37", 
     "typings": "^2.0.0", 
     "zone.js": "^0.6.12" 
    }, 
    "devDependencies": { 
     "gulp": "3.9.1", 
     "gulp-clean": "0.3.2", 
     "gulp-concat": "2.6.1", 
     "gulp-sourcemaps": "1.9.1", 
     "gulp-typescript": "3.1.3", 
     "gulp-uglify": "2.0.0", 
     "typescript": "2.0.10" 
    }, 
    "name": "kira", 
    "private": true, 
    "scripts": { 
     "postinstall": "typings install dt~core-js --global" 
    }, 
    "version": "1.0.0" 
} 

systemjs.config.js:

(function (global) { 
    System.config({ 
     paths: { 
      'npm:': 'node_modules/' 
     }, 
     map: { 
      app: 'wwwroot/app', 
      '@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', 
      '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js', 
      'rxjs': 'npm:rxjs' 
     }, 
     packages: { 
      app: { 
       main: './main.js', 
       defaultExtension: 'js' 
      }, 
      rxjs: { 
       defaultExtension: 'js' 
      } 
     } 
    }); 
})(this); 

我app.component.ts

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

@Component({ 
    selector: 'my-app', 
    template: `<h1>Hello {{name}}</h1>` 
}) 

export class AppComponent { name = 'Angular'; } 

回答

1

我最後在m之後纔開始工作任何時間!我需要問一個問題找到解決幾分鐘後...

我的問題是在我的tsconfig.json

我所用「模塊」:「系統」這是不工作(我不不知道爲什麼......)

我改變了這個'模塊':'commonjs',現在一切都在建設! :d

編輯:

我發現爲什麼「系統」是不工作的模塊,我tsconfig.json的原因。 因爲我使用Node.js模塊打包和節點使用commonjs來解壓這些模塊,所以我們需要將commonjs放在tsconfig中,這樣打字稿可以讀取它們。