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

Angular 2 failing to properly set headers for HTTP requests

My header and http call setup is as follows: var headers = new Headers(); headers.set('Authorization','Bearer xxxxxxxxxxx'); this.http.get('http://localhost:8080/outputEndpoints', { headers: headers }). map(res => res ...

React-query: When looping through useMutation, only the data from the last request can be accessed

Iterating over an array and applying a mutation to each element array?.forEach((item, index) => { mutate( { ...item }, { onSuccess: ({ id }) => { console.log(id) }, } ); }); The n ...

Why does using `withCredentials: true` and including a `body` in the request cause a CORS error in Angular HttpClient?

My objective is to make a request to a Cloud Function, receive a response with a Set-Cookie header, and have the browser store the cookie. The issue arises when the response containing a Set-Cookie header is ignored without the presence of withCredentials ...

I'm facing difficulty in assigning props because of the specific nature of generics in Typescript

My goal is to create a Higher Order Component (HOC) that can control a component which relies on certain props to function properly. To elaborate: I want to build a HOC that takes a component expecting props value and onChange, and modifies it so that the ...

Knexfile Doesn't Utilize TypeScript Paths

When attempting to run a migration, I encountered an issue with Knex. My Knexfile is in Typescript and uses path aliases from tsconfig.json. However, Knex is throwing an error stating Cannot find module '@foo-alias/bar-module'. What adjustments d ...

Please indicate the data type in Vue using Typescript

I'm currently struggling with Vue (3) + Typescript while attempting to specify a data property with a specific type. I have created a .d.ts file, but unfortunately, it hasn't helped. This is what I'm trying: import Modeler from 'bpmn-js ...

Exploring the process of iterating over asynchronous data in Angular

There is an angular component in my project that fetches data from the server, processes it, and then assigns it to a variable: class Component { data = []; ngOnInit() { this.store.select(data).pipe( map(data => { this.data = this.transf ...

Is there a way to transfer query parameters to my resolver function?

Here is how I initialize the component in my ngOnInit method: ngOnInit() { this.route.queryParams.subscribe( (params) => { console.log(params); } ) } This is my resolver code: class ProductsResolver implements Resolve< ...

Adding content in real-time at the current cursor position within a Contenteditable element using Angular

I have a contenteditable div where I am facing an issue with pasting text. Whenever I try to paste some text into the div, it always gets pasted at the end. I am using ViewChild to access the reference of the contenteditable div and utilizing innerText to ...

React: Issue with array rendering order after initial render

After the initial rendering of my array in the correct order, any subsequent changes to it result in the same rendered order. Let's consider this scenario: initializeArray() { this.state = { test_array: [1,2,3,4] } let self = t ...

Which is the optimal choice: subscribing from within a subscription or incorporating rxjs concat with tap?

After storing data in the backend, I proceed to retrieve all reserved data for that specific item. It is crucial that the data retrieval happens only after the reservation process to ensure its inclusion. Presented with two possible solutions, I am cont ...

Choosing the Right Language for AngularJS 2: TypeScript, JavaScript, or Dart?

AngularJS 2 is on the horizon, and the documentation recommends three languages: Typescript, Javascript, and Dart. As someone who primarily works with Javascript EcmaScript 5, I'm curious about the strengths and weaknesses of these three options. Cu ...

Issue arises when attempting to use the useEffect hook in React with Typescript to reset states upon the component unmounting

I'm facing an issue with my useEffect cleanup when the component unmounts and setting states simultaneously. My code involves selecting a client by clicking on them and setting their ID to send in an API request: const setClient = () => { setC ...

Flipping the Observable List in Angularfire2

Currently, I have implemented the following code to reverse the list: this.items = this.db.list('/privacy').map( (array) => {return array.reverse()} ) as FirebaseListObservable<any[]>; When displaying the list, I call it like this: &l ...

Utilizing Angular Services to Share Events and Reusing Components Multiple Times on a Page

My unique custom table is made up of multiple components, each emitting events using a shared service called TableEvent. These events are subscribed to by a class named TableTemplate, which facilitates communication among the different components of the ta ...

Combine es6 imports from the identical module using an Eslint rule or plugin

Looking to consolidate my ES6 imports from a single module into one for my React project. For example: import { Title } from "@mantine/core"; import { Center } from "@mantine/core"; import { Divider } from "@mantine/core"; T ...

Tips for verifying the input field with specific requirements in Angular 6

There is an input field that needs to validate text based on certain logic conditions: No spaces should be allowed in the formula. The operators (and,or) must be lowercase and enclosed in curly brackets {}. The number of opening '(&apos ...

What is the best way to transfer user data from the backend to the frontend?

I successfully created a replica of YelpCamp using Node and EJS, but now I am attempting to convert it into a Node-React project. Everything was going smoothly until I encountered an issue while trying to list a specific user in the SHOW route. In order to ...

Angular's HostListener triggers twice when the browser's back button is clicked

In my Angular application, I have implemented a @HostListener that triggers when the back button on the browser is clicked. However, I have noticed that the event handler seems to be firing twice - prompting two dialogue boxes when clicking 'Ok'. ...

The Windows platform is not recognizing the --port option when using ng serve

When running ng serve in Windows, it doesn't recognize the --port option. However, I found that it works if I use npm run ng serve --port portnumber and it always defaults to 4200: oml005@W7-2UA532159M MINGW64 /d/COT-TF/cot-web/cot-web (master) ng ...