When I try to ng build my Angular 11 application, why are the type definitions for 'Iterable', 'Set', 'Map', and other types missing?

As someone new to Angular and the node ecosystem, I'm facing a challenge that may be due to a simple oversight.

The issue at hand:

In my Angular 11 project within Visual Studio 2019, configured with Typescript 4, attempting to run the project through Visual Studio results in a 404 error page displaying "Cannot GET /". Likewise, running the project using ng build from the command line leads to an array of errors, primarily pointing out missing types such as Iterable, Set, and Map. For example:

Error: node_modules/rxjs/internal/types.d.ts:41:84 - error TS2304: Cannot find name 'Iterable'.

This error message surfaces multiple times even when setting the option to es2017 (using es2015 also yields the same errors):

Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.

I have searched for "Iterable" within my node_modules/@types folder but could not locate a definition, despite it being referenced in multiple places. I suspect I might be missing a types package, but I am unsure how to identify which one.

An Update:

This issue seems to stem from referencing certain type definitions at the top of one of my services:

///<reference path="../../../../node_modules/typescript/lib/lib.dom.d.ts" />
///<reference path="../../../../node_modules/typescript/lib/lib.d.ts" />

Omitting these references allows the project to build successfully, albeit resulting in numerous highlighted errors in Visual Studio due to missing definitions. On the other hand, adding "skipLibCheck": true, in my tsconfig.json enables the application to build temporarily but does not provide a lasting solution.

My troubleshooting attempts so far:

  • I have updated Node.js, NPM, Angular CLI, and all packages in my application.
  • Ensured that my package.json includes the latest version of @types/node.
  • Confirmed that my tsconfig.json targets es2015, with the lib compiler options containing "es2017" and "dom".
  • Verified that these are indeed the files used during the build process by inserting nonsense into them, leading to errors during ng build.
  • Deleted the node_modules folder and package-lock.json file, then reinstalled all packages with npm install.

My tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "incremental":  true, 
    "baseUrl": "./",
    "module": "es2020",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

My package.json:

{
  // Your package.json content here
}

My angular.json:

{
  // Your angular.json content here
}

Answer №1

The issue has been resolved successfully by identifying two key components.

Initially, it was unnecessary to include triple-slash directive references in my .ts file. As outlined in the typescript documentation, these statements are meant for use in typescript definition files only - "Use these directives only when you’re authoring a d.ts file by hand."

///<reference path="../../../../node_modules/typescript/lib/lib.dom.d.ts" />
///<reference path="../../../../node_modules/typescript/lib/lib.d.ts" />

Furthermore, encountering errors in my source files was due to missing references caused by ReSharper's inability to locate the definitions. Disabling the extension allowed regular intellisense to function properly.

The specific reason for ReSharper's difficulty in finding or reading the type definitions remains under investigation. Nonetheless, progress on the project can now resume. Any updates on resolving ReSharper's behavior will be shared accordingly.

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

How can I dynamically replace a specific element inside a .map() function with a custom component when the state updates, without replacing all elements at once?

I'm currently developing a task management application and I need to enhance the user experience by implementing a feature that allows users to update specific tasks. When a user clicks on the update button for a particular task, it should replace tha ...

Angular 6 throws an error stating: "The property 'push' cannot be read of null."

The Cart model is defined as follows: //declaring a cart model for products to add export class Cart{ id:string; name:string; quantity:number; picture:string; } Below is the code for my app.service.ts: import { Injectable, Inject } fro ...

Storing multiple strings in a string array in Angular2

Hi everyone, I’m just getting started with Angular and currently working on creating a recipe page that fetches data from an API. The API setup is complete, but now I need to figure out how to input the data into the API using Angular. I have defined a ...

Handling routerLink exceptions in Angular 2, 4, and 5

In my app, I am working on catching routing exceptions. There are three ways in which a user can navigate: If the user types the address directly - this can be caught easily by using { path: '**', redirectTo: 'errorPage'} in the route ...

Tips for deleting multiple objects from an array in angular version 13

I am facing an issue where I am trying to delete multiple objects from an array by selecting the checkbox on a table row. However, I am only able to delete one item at a time. How can I resolve this problem and successfully delete multiple selected objects ...

Refine current attributes of an object in Typescript

In typescript, I have an object of type any that needs to be reshaped to align with a specific interface. I am looking for a solution to create a new object that removes any properties not defined in the interface and adds any missing properties. An exam ...

Implement Php gettext functionality in Typescript

I have a keen interest in AngularJs 2, and I am planning to incorporate it into my upcoming project. I would like to integrate i18n with Php gettext. In a previous project, I utilized Php gettext by embedding Php within Javascript code as shown below: // ...

Another return payload failing to retrieve the return value

I'm currently facing an issue where a function that should return a value is not being passed on to another function. Below is the code snippet in question: public _getProfileToUpdate() { return { corporateId: this.storeService.setStoreData().p ...

Guide on upgrading an Angular project to a targeted version with its corresponding dependencies

I'm embarking on reviving a previous angular venture. My objective is to bring it up-to-date with a particular version along with upgrading all its affiliated dependencies to the most recent ones. I attempted by initially uninstalling the CLI version, ...

Passing props from pages to components in NextJS: A guide

My nextjs-application has a unique folder structure: components -- layouts --- header.tsx --- index.tsx pages -- index.tsx -- [slug].tsx In the [slug].tsx file, I utilize graphql to fetch data and set the props accordingly: export default ...

The Swagger-ui tool condenses objects into query parameters, while the angular client that it generates does not

I'm currently working on a Spring Boot application that includes the following Rest function: @SecuredMaster @GetMapping(path = "/mitarbeiter") @Operation(security = {@SecurityRequirement(name = "jwt")}) public Page<MitarbeiterListRow> getMitar ...

React TypeScript - Issue with passing props to Hooks causing type errors

I have set up a codesandbox project to demonstrate my problem 1) Initially, I created the <Input> component for styling and tracking input content. 2) While everything was functional, adding more forms prompted me to create a useInput hook for easi ...

Encountered a problem during the installation of firebase @angular/fire

I've been developing an Angular chat application and ran into some issues when trying to install Firebase using the command "npm install --save firebase @angular/fire". The installation resulted in a series of errors, with the main problem appearing t ...

What is the best method to consistently convert a deeply nested object into a tabular format that can be easily reversed

Imagine having a deeply nested object with an unknown structure until runtime, like: { "row-0" : { "rec-0" : { "date" : 20220121, "tags" : [ "val-0" ] }, ...

The rapid execution of code causing an observable race condition

When exporting a CSV file in my code, I encounter a race condition while trying to modify some data before the export. The issue is that the id gets set correctly, but the number only updates after the method is called a second time. I believe the proble ...

Request with missing authentication header in Swagger OpenAPI 3.0

When generating the swagger.json using tsoa for TypeScript, I encountered an issue. Even after adding an access token to the authorize menu in Swagger and making a request to one of my endpoints, the x-access-token header is missing from the request. What ...

Tips for adjusting card content to fit its size in material ui?

I'm looking to implement Material UI cards in a grid layout, each containing a Highcharts chart as shown in this demo. However, I'm facing an issue where the content does not adjust properly when the card size is fixed. How can I resolve this? A ...

The Next.js template generated using "npx create-react-app ..." is unable to start on Netlify

My project consists solely of the "npx create-react-app ..." output. To recreate it, simply run "npx create-react-app [project name]" in your terminal, replacing [project name] with your desired project name. Attempting to deploy it on Netlify Sites like ...

Attention: issue TS18002 has been detected - The 'files' configuration file is currently blank

I'm currently working with TypeScript version 2.1.5.0. My setup includes the grunt-typescript-using-tsconfig plugin, but I'm encountering an error when running the task. The issue seems to be related to the property "files":[] in my tsconfig.jso ...

Does property binding truly function as a one-way binding mechanism?

Recently, I began diving into Angular tutorials and came across an interesting point about Angular property binding. It seems that in this particular case, Angular property binding is a one-way binding, meaning that changes to the property of HeroComponent ...