错误TS2304:找不到名称' Map'。带有角度2和.net核心

时间:2017-03-27 09:42:37

标签: javascript angularjs json

我在Task Run Explorer中编译时从gulp获取此错误, 这很奇怪,因为我不会改变任何事情......无论如何,我在网上搜索并找到了一些解决方案但是没有工作。

错误1

  

...   node_modules/@angular/common/src/facade/lang.d.ts(11,17):错误   TS2304:找不到名称'地图'。   node_modules/@angular/common/src/facade/lang.d.ts(12,17):错误   TS2304:找不到名称' Set'。   node_modules/@angular/common/src/pipes/async_pipe.d.ts(41,38):错误   TS2304:找不到名字'承诺'。   ...

这是我的tsconfig.json

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

  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

这是我的package.json

{
  "version": "1.0.0",
  "name": "testapp.web",
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0-rc.5",
    "@angular/compiler": "2.0.0-rc.5",
    "@angular/core": "2.0.0-rc.5",
    "@angular/forms": "0.3.0",
    "@angular/http": "2.0.0-rc.5",
    "@angular/platform-browser": "2.0.0-rc.5",
    "@angular/platform-browser-dynamic": "2.0.0-rc.5",
    "@angular/router": "3.0.0-rc.1",
    "@angular/upgrade": "2.0.0-rc.5",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "^0.19.37",
    "typings": "^2.1.0",
    "zone.js": "^0.6.12"
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-clean": "^0.3.2",
    "gulp-concat": "^2.6.0",
    "gulp-less": "^3.1.0",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-typescript": "^2.13.6",
    "gulp-uglify": "^2.0.0",
    "typescript": "^2.2.1" 
  },
  "scripts": {
    "postinstall": "typings install dt~core-js --global"
  }
} 

**用解决方案修改**

新tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "system",
    "moduleResolution": "node",
    "noImplicitAny": false,
    "noEmitOnError": false,
    "removeComments": false,
    **"target": "es6" <<-- CHANGE**
  },

  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

new package.json

{
  "version": "1.0.0",
  "name": "testapp.web",
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0-rc.5",
    "@angular/compiler": "2.0.0-rc.5",
    "@angular/core": "2.0.0-rc.5",
    "@angular/forms": "0.3.0",
    "@angular/http": "2.0.0-rc.5",
    "@angular/platform-browser": "2.0.0-rc.5",
    "@angular/platform-browser-dynamic": "2.0.0-rc.5",
    "@angular/router": "3.0.0-rc.1",
    "@angular/upgrade": "2.0.0-rc.5",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "^0.19.37",
    "typings": "^2.1.0",
    "zone.js": "^0.6.12",
    **"es6-promise": "3.2.1",  <<-- CHANGE
    "es6-shim": "0.35.1"**
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-clean": "^0.3.2",
    "gulp-concat": "^2.6.0",
    "gulp-less": "^3.1.0",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-typescript": "^2.13.6",
    "gulp-uglify": "^2.0.0",
    "typescript": "^2.2.1" 
  },
  "scripts": {
    "postinstall": "typings install dt~core-js --global"
  }
}

获取此错误..

  

GulpUglifyError:无法缩小JavaScript

如果我做第二个解决方案,我可以用旧浏览器的兼容性问题吗?

1 个答案:

答案 0 :(得分:0)

这是我的gulp.js

var gulp = require('gulp'),
    gp_clean = require('gulp-clean'),
    gp_concat = require('gulp-concat'),
///    gp_less = require('gulp-less'),
    gp_sourcemaps = require('gulp-sourcemaps'),
    gp_typescript = require('gulp-typescript'),
    gp_uglify = require('gulp-uglify');
    gp_pump = require('pump');

/// 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/**'
    ]
    ///,
    ///less: [
    ///    'Scripts/less/**/*.less'
    ///]
};

var destPaths = {
    app: 'wwwroot/app/',
    css: 'wwwroot/css',
    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(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(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 }));
});

//// Process all LESS files and output the resulting CSS in wwwroot/css
///gulp.task('less', ['less_clean'], function () {
///    return gulp.src(srcPaths.less)
///        .pipe(gp_less())
///        .pipe(gulp.dest(destPaths.css));
//});

//// Delete wwwroot/css contents
///gulp.task('less_clean', function () {
///    return gulp.src(destPaths.css + "*.*", { 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']);
});

gulp.task('compress', function (cb) {
    pump([
          gulp.src(srcPaths.js),
          uglify(),
          gulp.dest(destPaths.js)
    ],
      cb
    );
});

// 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']);