gulp任务运行器给出错误

时间:2016-11-13 06:20:04

标签: angular visual-studio-2015

我在为“gulp”文件执行任务运行时遇到错误,我的示例项目是使用Angular 2和Asp.net Core。

我有“typings”文件夹,它位于“typings.json”文件下面,

{   “决议”:“主要”,   “树”:{     “src”:“https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/be0ba281b67575b3b626a6bbb15b152add97244e/core-js/core-js.d.ts”,     “raw”:“registry:dt / core-js#0.0.0 + 20160914114559”,     “typings”:“https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/be0ba281b67575b3b626a6bbb15b152add97244e/core-js/core-js.d.ts”   } }

enter image description here

以下是我的“gulp”文件,

/*
This file in the main entry point for defining Gulp tasks and using Gulp plugins.
Click here to learn more. http://go.microsoft.com/fwlink/?LinkId=518007
*/
var gulp = require('gulp'),
    gp_clean = require('gulp-clean'),
    gp_concat = require('gulp-concat'),
    gp_sourcemaps = require('gulp-sourcemaps'),
    gp_typescript = require('gulp-typescript'),
    gp_uglify = require('gulp-uglify');



// Define paths
var srcPaths = {
    app: ['Scripts/app/main.ts', 'Scripts/app/**/*.ts'],
    js: [
    'Scripts/js/**/*.js',
    'node_modules/core-js/client/shim.min.js',
    'node_modules/zone.js/dist/zone.js',
    'node_modules/reflect-metadata/Reflect.js',
    'node_modules/systemjs/dist/system.src.js',
    'node_modules/typescript/lib/typescript.js'
    ],
    js_angular: [
    'node_modules/@angular/**'
    ],
    js_rxjs: [
    'node_modules/rxjs/**'
    ]
};

var destPaths = {
    app: 'wwwroot/app/',
    js: 'wwwroot/js/',
    js_angular: 'wwwroot/js/@angular/',
    js_rxjs: 'wwwroot/js/rxjs/'
};

// Compile, minify and create sourcemaps all TypeScript files and place
//them to wwwroot/app, together with their js.map files.

gulp.task('app', ['app_clean'], function () {
    return gulp.src(srcPaths.app)
        .pipe(gp_sourcemaps.init())
        //.pipe(plugins.typescript(tsProject))
        .pipe(gp_typescript(require('./tsconfig.json').compilerOptions))
        .pipe(gp_uglify({ mangle: false }))
        .pipe(gp_sourcemaps.write('/'))
        .pipe(gulp.dest(destPaths.app));
});

// Delete wwwroot/app contents
gulp.task('app_clean', function () {
    return gulp.src(destPaths.app + "*", { read: false })
    .pipe(gp_clean({ force: true }));
});

// Copy all JS files from external libraries to wwwroot/js
gulp.task('js', function () {
    gulp.src(srcPaths.js_angular)
        .pipe(gulp.dest(destPaths.js_angular));
    gulp.src(srcPaths.js_rxjs)
    .pipe(gulp.dest(destPaths.js_rxjs));
    return gulp.src(srcPaths.js)
    // .pipe(gp_uglify({ mangle: false })) // disable uglify
    // .pipe(gp_concat('all-js.min.js')) // disable concat
    .pipe(gulp.dest(destPaths.js));
});

// Delete wwwroot/js contents
gulp.task('js_clean', function () {
    return gulp.src(destPaths.js + "*", { read: false })
    .pipe(gp_clean({ force: true }));
});

// Watch specified files and define what to do upon file changes
gulp.task('watch', function () {
    gulp.watch([srcPaths.app, srcPaths.js], ['app', 'js']);
});

// Global cleanup task
gulp.task('cleanup', ['app_clean', 'js_clean']);

// Define the default task so it will launch all other tasks
gulp.task('default', ['app', 'js', 'watch']);

以下是67错误,

C:\01Work\OpenGameList\src\OpenGameListWebApp> cmd.exe /c gulp -b "C:\01Work\OpenGameList\src\OpenGameListWebApp" --color --gulpfile "C:\01Work\OpenGameList\src\OpenGameListWebApp\Gulpfile.js" default
[11:39:57] Using gulpfile C:\01Work\OpenGameList\src\OpenGameListWebApp\Gulpfile.js
[11:39:57] Starting 'app_clean'...
[11:39:57] Starting 'js'...
[11:39:57] Starting 'watch'...
[11:39:57] Finished 'watch' after 37 ms
[11:39:58] Finished 'app_clean' after 543 ms
[11:39:58] Starting 'app'...
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/common/src/directives/ng_class.d.ts(46,34): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/common/src/pipes/async_pipe.d.ts(39,38): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/compile_metadata.d.ts(347,20): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/compile_metadata.d.ts(348,15): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/directive_normalizer.d.ts(19,100): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/directive_normalizer.d.ts(21,74): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/offline_compiler.d.ts(15,26): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/offline_compiler.d.ts(16,38): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/offline_compiler.d.ts(31,124): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/output/output_ast.d.ts(424,63): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/resource_loader.d.ts(13,23): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/runtime_compiler.d.ts(40,49): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/runtime_compiler.d.ts(42,65): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/template_parser/template_parser.d.ts(45,12): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/util.d.ts(35,18): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/util.d.ts(36,46): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/view_compiler/compile_element.d.ts(33,16): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/view_compiler/compile_query.d.ts(24,49): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/view_compiler/compile_view.d.ts(29,18): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/view_compiler/compile_view.d.ts(52,16): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/compiler/src/view_compiler/compile_view.d.ts(54,13): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/application_init.d.ts(16,18): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/application_ref.d.ts(106,67): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/application_ref.d.ts(122,101): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/application_ref.d.ts(148,67): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/application_ref.d.ts(150,101): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(24,15): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(28,16): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/di/reflective_provider.d.ts(88,123): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/di/reflective_provider.d.ts(88,165): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'MapConstructor'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(3,25): error TS2304: Cannot find name 'SetConstructor'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(5,27): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(5,39): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(8,9): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(9,30): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(12,43): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(13,27): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(15,23): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(16,25): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(101,41): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(102,22): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/collection.d.ts(103,25): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/lang.d.ts(12,17): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/lang.d.ts(13,17): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/facade/lang.d.ts(51,59): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/linker/compiler.d.ts(53,49): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/linker/compiler.d.ts(61,65): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/linker/ng_module_factory_loader.d.ts(14,34): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/core/src/linker/system_js_ng_module_factory_loader.d.ts(28,25): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/http/src/headers.d.ts(45,59): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/http/src/url_search_params.d.ts(46,16): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser-dynamic/src/resource_loader/resource_loader_impl.d.ts(10,23): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(79,33): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/dom/dom_adapter.d.ts(97,42): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/dom/dom_renderer.d.ts(18,37): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'MapConstructor'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(3,25): error TS2304: Cannot find name 'SetConstructor'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(5,27): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(5,39): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(8,9): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(9,30): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(12,43): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(13,27): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(15,23): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(16,25): error TS2304: Cannot find name 'Map'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(101,41): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(102,22): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/@angular/platform-browser/src/facade/collection.d.ts(103,25): error TS2304: Cannot find name 'Set'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/rxjs/Observable.d.ts(68,60): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/rxjs/Observable.d.ts(68,70): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/rxjs/observable/PromiseObservable.d.ts(40,31): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/rxjs/observable/PromiseObservable.d.ts(41,26): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/rxjs/operator/toPromise.d.ts(8,60): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/rxjs/operator/toPromise.d.ts(9,79): error TS2304: Cannot find name 'Promise'.
C:/01Work/OpenGameList/src/OpenGameListWebApp/node_modules/rxjs/operator/toPromise.d.ts(9,89): error TS2304: Cannot find name 'Promise'.
[11:40:03] TypeScript: 76 semantic errors
[11:40:03] TypeScript: emit succeeded (with errors)
[11:40:03] Finished 'js' after 6.2 s
[11:40:03] Finished 'app' after 5.69 s
[11:40:03] Starting 'default'...
[11:40:03] Finished 'default' after 8.93 μs

1 个答案:

答案 0 :(得分:0)

您没有包含与TypeScript版本相关的任何信息,但我认为它的TS> = 2.0。

在这种情况下,您需要在package.json中包含@types/core-js。除此之外,您需要在tsconfig.json中指向core-js类型(或tsconfig-aot.json)

"typeRoots": [ "./node_modules/@types" ]

如果您手动指定所有类型,那么......

"typeRoots": [ "./node_modules/@types" ], "types": [ "core-js", ...(other types you manually specify) ]

希望它有所帮助。