0
votes

I am trying to implement Angular 2 with help of gulp in .Net Core using visual Studio update 3 with npm version 4.4.4 and node version v6.10.0 and already installed Typescript tool. All are

here is my Github link

And quick description of code

1.gulpfile.js

    /// <binding BeforeBuild='libs' Clean='clean' />

    var gulp = require('gulp');
    var rimraf = require('rimraf')
    var paths = {
        npm: './node_modules/',
        lib: './wwwroot/lib/'
    };
    var libs = [
       paths.npm + 'core-js/client/shim.min.js',
       paths.npm + 'zone.js/dist/zone.js',
       paths.npm + 'reflect-metadata/Reflect.js',
       paths.npm + 'systemjs/dist/system.src.js'
    ];
    gulp.task('libs', function () {
        return gulp.src(libs).pipe(gulp.dest(paths.lib));
    });
    gulp.task('clean', function (callback) {
        rimraf(paths.lib, callback);
    });

2. package.json

{
    "version": "1.0.0",
    "name": "asp.net",
  "private": true,
  "dependencies": {
    "@angular/common": "~2.4.0",
    "@angular/compiler": "~2.4.0",
    "@angular/core": "~2.4.0",
    "@angular/forms": "~2.4.0",
    "@angular/http": "~2.4.0",
    "@angular/platform-browser": "~2.4.0",
    "@angular/platform-browser-dynamic": "~2.4.0",
    "@angular/router": "~3.4.0",

    "angular-in-memory-web-api": "~0.2.1",
    "systemjs": "0.19.40",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.1",
    "zone.js": "^0.7.4"
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "rimraf": "^2.6.1"
  }
}

3. tsconfig.json

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "module": "commonjs",
    "outDir": "wwwroot/app/",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "exclude": [
    "node_modules",
    "wwwroot/lib",
    "wwwroot/app"
  ]
}

4. typings.json

{
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160725163759",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "node": "registry:dt/node#6.0.0+20160909174046"
  }
}

And all other files from my last question

project build successfully but got error while executing like below

enter image description here

Please help me, What exactly I am missing?

1

1 Answers

0
votes

first thing use of systemjs.config,js file is missing so add it and as per systemjs.config.js file change in gulpfile for required angular dependent files so here is a change

  1. gulpfile.js /////

    //var gulp = require('gulp');
    //var rimraf = require('rimraf')
    //var paths = {
    //    npm: './node_modules/',
    //    lib: './wwwroot/lib/'
    //};
    //var libs = [
    //   paths.npm + 'core-js/client/shim.min.js',
    //   paths.npm + 'zone.js/dist/zone.js',
    //   paths.npm + 'reflect-metadata/Reflect.js',
    //   paths.npm + 'systemjs/dist/system.src.js'
    //];
    //gulp.task('libs', function () {
    //    return gulp.src(libs).pipe(gulp.dest(paths.lib));
    //});
    //gulp.task('clean', function (callback) {
    //    rimraf(paths.lib, callback);
    //});
    
    
    var gulp = require('gulp');
    
    var libs = './wwwroot/libs/';
    
    gulp.task('default', function () {
        // place code for your default task here
    });
    
    gulp.task('restore:core-js', function () {
        gulp.src([
            'node_modules/core-js/client/*.js'
        ]).pipe(gulp.dest(libs + 'core-js'));
    });
    gulp.task('restore:zone.js', function () {
        gulp.src([
            'node_modules/zone.js/dist/*.js'
        ]).pipe(gulp.dest(libs + 'zone.js'));
    });
    gulp.task('restore:reflect-metadata', function () {
        gulp.src([
            'node_modules/reflect-metadata/reflect.js'
        ]).pipe(gulp.dest(libs + 'reflect-metadata'));
    });
    gulp.task('restore:systemjs', function () {
        gulp.src([
            'node_modules/systemjs/dist/*.js'
        ]).pipe(gulp.dest(libs + 'systemjs'));
    });
    gulp.task('restore:rxjs', function () {
        gulp.src([
            'node_modules/rxjs/**/*.js'
        ]).pipe(gulp.dest(libs + 'rxjs'));
    });
    gulp.task('restore:angular-in-memory-web-api', function () {
        gulp.src([
            'node_modules/angular-in-memory-web-api/**/*.js'
        ]).pipe(gulp.dest(libs + 'angular-in-memory-web-api'));
    });
    
    gulp.task('restore:angular', function () {
        gulp.src([
            'node_modules/@angular/**/*.js'
        ]).pipe(gulp.dest(libs + '@angular'));
    });
    
    gulp.task('restore:bootstrap', function () {
        gulp.src([
            'node_modules/bootstrap/dist/**/*.*'
        ]).pipe(gulp.dest(libs + 'bootstrap'));
    });
    
    gulp.task('restore', [
        'restore:core-js',
        'restore:zone.js',
        'restore:reflect-metadata',
        'restore:systemjs',
        'restore:rxjs',
        'restore:angular-in-memory-web-api',
        'restore:angular',
        'restore:bootstrap'
    ]);
    
  2. index.html file under wwwroot folder

    <html>
    <head>
        <title>Angular QuickStart</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="styles.css">
        <!-- 1. Load libraries -->
        <!-- Polyfill(s) for older browsers -->
        <script src="libs/core-js/shim.min.js"></script>
        <script src="libs/zone.js/zone.js"></script>
        <script src="libs/reflect-metadata/Reflect.js"></script>
        <script src="libs/systemjs/system.src.js"></script>
        <!-- 2. Configure SystemJS -->
        <script src="systemjs.config.js"></script>
        <script>
            System.import('app').catch(function (err) { console.error(err); });
        </script>
    </head>
    <!-- 3. Display the application -->
    <body>
        <my-app>Loading...</my-app>
    </body>
    </html>
    

and most important 3.systemjs.config.js file

    /**
     * System configuration for Angular samples
     * Adjust as necessary for your application needs.
     */
    (function (global) {
        System.config({
            paths: {
                // paths serve as alias
                'npm:': 'libs/'
            },
            // 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',
                // other libraries
                'rxjs': 'npm:rxjs',
                'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
            },
            // packages tells the System loader how to load when no filename and/or no extension
            packages: {
                app: {
                    main: './main.js',
                    defaultExtension: 'js'
                },
                rxjs: {
                    defaultExtension: 'js'
                },
                'angular-in-memory-web-api': {
                    main: './index.js',
                    defaultExtension: 'js'
                }
            }
        });
    })(this);

updated code at Github