Issue TS2304: Unable to locate reference to 'Map' in the context of using Angular 2 with .NET Core

While compiling in Task Run Explorer, I encountered an error from gulp that took me by surprise since I didn't make any changes. Despite searching online for solutions, none of them seemed to work.

ERROR 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(12,17): error TS2304: Cannot find name 'Set'. node_modules/@angular/common/src/pipes/async_pipe.d.ts(41,38): error TS2304: Cannot find name 'Promise'. ...

This is my 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"
  ]
}

Here is my package.json:

{
  "version": "1.0.0",
  "name": "testapp.web",
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0-rc.5",
    ...
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    ...
  },
  "scripts": {
    "postinstall": "typings install dt~core-js --global"
  }
} 

Modified with the solution found:

New tsconfig.json:

{
  ...
  **"target": "es6" <<-- CHANGE**
  ...
}

New package.json:

{
  ...
    **"es6-promise": "3.2.1",  
    "es6-shim": "0.35.1"**
  ...
}

I now encounter this error:

GulpUglifyError: unable to minify JavaScript

If I implement the second solution, will it cause compatibility issues with older browsers?

Answer №1

Here is an example of my gulp.js configuration:

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/'
};

// Task to compile, minify and create sourcemaps for all TypeScript 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));
});

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

// Task to copy 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));
});

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

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

//// Task to clean wwwroot/css contents
///gulp.task('less_clean', function () {
///    return gulp.src(destPaths.css + "*.*", { read: false })
///        .pipe(gp_clean({ force: true }));
//});

// Task to watch specified files for 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']);

// Default task to launch all other tasks
gulp.task('default', ['app', 'js', 'watch']);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Condense Javascript Function

I created a function for turning strings into abbreviations, but it's currently quite lengthy and case-sensitive. I'm looking for a way to streamline it so that it functions flawlessly all the time. Right now, it messes up if a splitting word is ...

Transforming a JSONP request to automatically parse a text response into JSON

If I have the following request $.ajax({ type: "GET", dataType: "jsonp", jsonp: "callback", jsonpCallback: "my_callback", url: my_https_url, headers:{"Content-Type":"text/html; charset=utf-8"}, success: function(data) { ...

What is the best way to insert distinct values into an array in mongoDB?

I have a table of likes, and within that table, there is an array called videoLikes. I want to store the userData of users who have liked the video. However, when I attempt to add an object with a userId field to that array, I end up with duplicate data. S ...

Please ensure that the data has fully loaded before initializing the component

I am currently working with Angular 1.5 and have a scenario where I have one component nested within another component, as shown below. The issue I am facing is that the data variable is not resolved by the time Angular triggers the component-child, result ...

The ng-click function seems to be malfunctioning within the Angular JS framework

Whenever a list element is clicked, I want to change the scope value and also trigger an onclick function. However, in this particular code, ng-click is not functioning when we add a label for the list element. Here is the code snippet: <ul class="" ...

Collect information using Python's request module

import requests from pprint import pprint headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36', } params = ( ('LeagueID', &ap ...

Having trouble logging JSON data from nodejs + express while serving static files through express. However, I am able to see the data when I only make a GET request for the JSON data without the static files

Currently, I am experimenting with sending data from a nodejs + express server to the front-end static files. The objective is for JavaScript (allScripts.js) on the front-end to process this data. At this stage, my aim is to log the data to the console to ...

Is there a way to transform a form-check (radio button) into a 5-point slider on an HTML/JS webpage?

I have developed a survey page and I would like to transform the survey question from a radio button to a 5-point slider. I attempted to utilize the following code snippet: <input id="ex1" data-slider-id='ex1Slider' type="text&q ...

A guide to showcasing data within PrimeNG's pie chart component using either JavaScript or Angular

I have utilized the pie chart feature from the PRIMENG CHART PLUGIN My goal is to showcase the values within a pie chart Below, you can find my code for reference **Within app.component.html** <div style="display: block"> <p-chart type="pi ...

Implement a method within a directive

Check out my custom Angular directive code below, which generates div elements: function footerDirective($compile){ return { link: function(scope,elements,attributes){ function createDiv(content,cname,callback){ ...

Utilizing Vue.js: Disabling button on image carousel when there is no "next" photo accessible

This is my initial experience with Vue. I am attempting to assemble a slideshow using an array of images. I have successfully managed to disable the "previous" button when the user reaches the beginning of the slideshow, but I am encountering difficulties ...

Despite calling Bootstrap Switch JS, no action is being executed

Struggling with integrating Bootstrap Switch into my project that already uses Bootstrap and jQuery. It seems like the JavaScript isn't affecting the HTML, which is driving me crazy. I've tried adding Bootstrap Switch using both the gem and stra ...

Acquire the S3 URL link for the uploaded file upon completion of the file upload process

Is there a way to securely upload and generate a public Amazon S3 URL for a PDF file when a user clicks on a specific link? I'd like to avoid exposing the actual link to the user by uploading it to S3. Here's a sample code snippet: module.expo ...

Create a new API by expanding upon an already established API

In my application, I have several controllers whose sole purpose is to retrieve specific data from MongoDB for my views. Instead of constantly using the ugly and unreadable mongoose code in all controllers where database access is required, I decided to cr ...

Managing AJAX requests using Express JS

Currently facing an issue with handling ajax requests using ExpressJS. Whenever I click on an anchor tag, the entire page reloads instead of handling the ajax request on the client side. I am looking to ensure that clicking on any of these links triggers ...

Summarize the array of objects and find the average value for each distinct object name

I'm facing a challenge with an array structure: const originalArray = [ { name: "a", value: 1 }, { name: "a", value: 2 }, { name: "a", value: 3 }, { name: "b", ...

Encountering Reference Error while Using AWS Amplify with Nuxt.js: Navigator Undefined

Currently, I am experimenting with Nuxt.js and AWS Amplify to leverage the benefits of SSR/SEO for my project. I have successfully integrated Amplify into my project and followed the "Manual Configuration" steps outlined in the Amplify Docs to set it up. ...

What is the easiest way to locate the ID of an iframe embedded within a webpage?

Currently, I am focused on developing small JavaScript/HTML5 ads for a webpage. Each advertisement comes with its own iframe that occupies a specific size and space on the page. In order to accommodate an expandable ad that needs to surpass the predetermin ...

Prohibit the use of screen printing in a modern web application developed with Angular or ReactJS

Is there a way to prevent screen capturing and recording, specifically in regards to progressive web apps? While some mobile applications offer this feature, I am curious about the feasibility of implementing it in progressive web apps without requiring an ...

Choosing an item from a list using React-Redux

Currently learning React, I am facing some challenges in selecting an item from a list of recipes. My main focus right now is on deleting a recipe from the list, but before that, I need to understand how to identify and select a specific recipe. For refer ...