简体   繁体   English

错误TS2304:找不到名称“地图”。 具有angular 2和.net核心

[英]error TS2304: Cannot find name 'Map'. with angular 2 and .net core

I obtain this error from a gulp when I compile in Task Run Explorer, It strange because I don't change anythings ... anyway I search on line and found a few solution but dosen't work. 当我在Task Run Explorer中进行编译时,我从大口吃中获得了此错误,这很奇怪,因为我没有进行任何更改...无论如何,我在网上搜索并找到了一些解决方案,但没有用。

ERROR 1 错误1

... node_modules/@angular/common/src/facade/lang.d.ts(11,17): error TS2304: Cannot find name 'Map'. ... node_modules/@angular/common/src/facade/lang.d.ts(11,17):错误TS2304:找不到名称“地图”。 node_modules/@angular/common/src/facade/lang.d.ts(12,17): error TS2304: Cannot find name 'Set'. node_modules/@angular/common/src/facade/lang.d.ts(12,17):错误TS2304:找不到名称“设置”。 node_modules/@angular/common/src/pipes/async_pipe.d.ts(41,38): error TS2304: Cannot find name 'Promise'. node_modules/@angular/common/src/pipes/async_pipe.d.ts(41,38):错误TS2304:找不到名称“ Promise”。 ... ...

This my tsconfig.json 这是我的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"
  ]
}

and this my package.json 这是我的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"
  }
} 

** Modified with solution found** **修改为找到的解决方案**

new tsconfig.json 新的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 新的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"
  }
}

Obtain this error.. 获取此错误。

GulpUglifyError: unable to minify JavaScript GulpUglifyError:无法缩小JavaScript

If I do the second solution, can I problem with the compatibilty wiht old browser? 如果我做第二种解决方案,我可以与旧的浏览器兼容吗?

This is my gulp.js 这是我的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']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM