TypeScript is throwing an error because it is unable to recognize the identifiers such as WeakMap

Currently, I am in the process of learning Angular and have set up my TypeScript and Webpack configurations as follows:

Here is my tsconfig file:

{
"compilerOptions": {
  "target": "es5",
  "module": "es2015",
  "moduleResolution": "node",
  "sourceMap": true,
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "lib": ["es6", "dom"],
  "noImplicitAny": true,
  "suppressImplicitAnyIndexErrors": true,
  "typeRoots": [
    "node_modules/@types/"
  ]
},
"exclude": [
    "node_modules"
]

Now, let's take a look at my webpack.config.js file:

    var path = require('path');
var webpack = require('webpack');
var UglifyJSPlugin = require('uglifyjs-webpack-plugin'); 
module.exports = {
    entry: {
        'polyfills': './src/polyfills.ts',
        'app': './src/main.ts'
      },
   output:{
       path: path.resolve(__dirname, './public'),    
       publicPath: '/public/',
       filename: "[name].js"      
   },
   resolve: {
    extensions: ['.ts', '.js']
  },
   module:{
       rules:[   
           {
               test: /\.ts$/, 
               use: [
                {
                    loader: 'awesome-typescript-loader',
                    options: { configFileName: path.resolve(__dirname, 'tsconfig.json') }
                  } ,
                   'angular2-template-loader'
               ]
            }
       ]
   },
   plugins: [
    new webpack.ContextReplacementPlugin(
        /angular(\\|\/)core/,
        path.resolve(__dirname, 'src'), 
      {} 
    ),
    new UglifyJSPlugin()
  ]
}

Below are links to screenshots of my project layout:

Screen

However, when I try to run the project, I encounter the following errors:

ERROR in [at-loader] ./node_modules/@types/node/index.d.ts:6208:55 TS2304: Cannot find name 'Map'.

ERROR in [at-loader] ./node_modules/@types/node/index.d.ts:6215:55 TS2304: Cannot find name 'Set'.

ERROR in [at-loader] ./node_modules/@types/node/index.d.ts:6225:59 TS2304: Cannot find name 'WeakMap'.

ERROR in [at-loader] ./node_modules/@types/node/index.d.ts:6226:59 TS2304: Cannot find name 'WeakSet'.

If you'd like to see the full terminal log for these errors, please click on the link below:

https://pastebin.com/jyRLSn42

Can anyone advise me on how to address these issues?

Answer №1

Get the corejs types installed

npm install --save-dev @types/core-js

Don't forget to include it in tsConfig as well

{
"compilerOptions": {
  "target": "es5",
  "module": "es2015",
  "moduleResolution": "node",
  "sourceMap": true,
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "lib": ["es6", "dom"],
  "noImplicitAny": true,
  "suppressImplicitAnyIndexErrors": true,
  "typeRoots": [
    "node_modules/@types/"
  ],
  "types": [
     "core-js"
   ]
},

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

Experiencing trouble accessing a property in TypeScript

While working on my Next.js project, I have encountered a specific issue related to selecting the Arabic language. The translation functions correctly and the text is successfully translated into Arabic. However, the layout does not switch from its default ...

Parsing temporary storage of database query results

My experience with OOP languages like C# and Java has been good, but I am relatively new to JavaScript/TypeScript. I find callback functions confusing, especially when using them with the BaaS ParseDB. For example, finding all playlists for a certain user ...

Fixing the Material UI upgrade error: "Make sure you have the right loader for this file type."

As a beginner in React, Webpack, Babel, and web development, I have been tasked by my company to upgrade the material-ui version for a dropdown search component. The current version used in the project is "1.0.0-beta.43", and I decided to start by upgradin ...

Transfer all the child nodes to the parent using the spread operator or Object.assign while preventing duplicate properties from being overwritten

I'm trying to transfer all the nodes of a child node to the parent using the spread operator or Object.assign (without relying on Lodash) while avoiding overwriting existing properties. My initial thought was to simply append the childArray to the ro ...

What is the best way to support multiple locales simultaneously in an Angular 7 application?

During the development of my app, I am looking to seamlessly switch between multiple supported locales. However, I have been unable to figure out how to serve the app with all these locales. Is there a way to achieve this without resorting to any workarou ...

Guide to executing specific functions based on selected dropdown options in Angular 5

Several drop down menus need to be implemented. The requirement is that when an option from the drop-down is selected, a corresponding custom function should be called. However, in the code below, what should replace opt.mtd since it is not functioning as ...

There are no versions available for Angular NPM that match [email protected]

Here is the contents of my .npmrc file: registry=https://pkgs.dev.azure.com/<yourOrganization>/_packaging/<yourFeed>/npm/registry/ always-auth=true After deleting node_modules and attempting to install the packages, I encountered the follo ...

Implementing conditional asynchronous function call with identical arguments in a Typescript React project

Is there a way in React to make multiple asynchronous calls with the same parameters based on different conditions? Here's an example of what I'm trying to do: const getNewContent = (payload: any) => { (currentOption === myMediaEnum.T ...

Is it possible to utilize Typescript and Browserify in tandem?

As I explore the compatibility of TypeScript and Browserify, one perplexing aspect stands out - they both utilize 'require' but for different purposes. TypeScript uses 'require' to import other TS modules, while Browserify employs it to ...

A reference to 'this' is not permissible within a static function in Types

Based on this GitHub issue, it is stated that referencing this in a static context is allowed. However, when using a class structure like the following: class ZController { static async b(req: RequestType, res: Response) { await this.a(req) ...

React JS and Webpack encountering issue 'Unable to locate module 'webpack-cli/bin/config-yargs'' while running 'npm run start'

I have recently embarked on creating a React JS project from scratch, utilizing Webpack to compile assets and aid in development. However, I am encountering some issues when attempting to execute "npm run start." Below is a snippet of my package.json file ...

After calling the PHP API, the http.get method in Ionic 2 is returning a value of isTr

Even though a similar question has been posted before, I am still puzzled about why I am receiving: 'isTrusted': true every time I call a PHP API from Ionic 2. The code I am using is as follows: getProduct(id: string){ if(this._product){ con ...

Encountered an error while attempting to install the 'ionic-native' package

Currently, I am navigating through this particular link to integrate local notifications into my Ionic 2 application. To kickstart the process, I executed the following two commands: Username@DESKTOP-BNKQVBC MINGW64 ~/Reminder-App (platform-specific) $ n ...

When hovering over a province on Jvectormap, the name of the province is

Currently, I am working on implementing a jvectormap for The Netherlands. However, I am facing an issue where a double nametag of the province appears when I hover over the map. https://i.sstatic.net/NCTzZ.png HTML Implementation <div id="worldMap" ...

Awaiting the asynchronous call in Angular 2 and beyond

Here is a method I am working with: prepareCalendarDaysToAdd() { this.getDaysToAdd(); //first line this.dataSaved.emit(this.daysToAdd); //second line } The getDaysToAdd() method makes an asynchronous call: getDaysToAdd() { this.da ...

Is it possible for "canActivate" to receive data?

In the configuration of my router, I have specified the following lines: .. canActivate: [MyGuard], path: "search", component: SearchComponent, data: { accessRoles: [roleAdmin, roleUser] } .. I am aiming to restrict access to ...

Changes were made to React Context, however, the components are not reflecting these updates

I've been experimenting with implementing the Context API using hooks in our company project. We're working with TypeScript. I've set up a Context, a Provider, and a Reducer. However, when I interact with buttons, the state changes but the c ...

Ways to utilize a previous acquisition

After purchasing a consumable product, I forgot to consume it during my release. I made changes to my code so now the unpurchased products are not available for purchase anymore. When I attempted to use restorePurchases to consume the products that were n ...

What is the method for extracting user input from a text box on a webpage?

Having trouble with retrieving the value from a text box in my search function. SearchBar Component import { Component, OnInit, Input } from '@angular/core'; @Component({ selector: 'app-search', templateUrl: './search.compon ...

What are the benefits of maintaining a property as non-observable instead of observable in knockout.js?

In my TypeScript project utilizing Knockout.js, I have a class with several properties. One of these properties is 'description', which is not directly tied to the DOM but needs to be used in popups triggered by certain mouse events (such as butt ...