2016-11-28 213 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中,这样打字稿可以读取它们。