What could be the reason for receiving the error message "NgModule' is not found" even after executing the command "npm i @types/node --global"?

Even though I tried following the suggestions provided in this Stack Overflow thread, I am still encountering the error "TypeScript error in Angular2 code: Cannot find name 'module'". My development environment consists of Angular 5 and npm version 6.9.0. Currently, I am working on a tutorial that can be found here - .

In my ./src/app/app.component.ts file, I have the following code snippet at the top:


import { Component,trigger,animate,style,transition,keyframes } from '@angular/core';
import { FormsModule }   from '@angular/forms';

@NgModule({
  imports: [
             BrowserModule,
             FormsModule      //<----------make sure you have added this.
           ],
})

Upon running the application, I encounter the following error message:


localhost:todo-app davea$ ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2019-05-17T17:06:29.377Z                                                       
Hash: e9b5158cd1cb6d5685c7
Time: 2561ms
chunk {inline} inline.bundle.js (inline) 3.85 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 2.91 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 577 bytes [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 41.6 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 867 kB [initial] [rendered]

ERROR in src/app/app.component.ts(4,2): error TS2552: Cannot find name 'NgModule'. Did you mean 'module'?
src/app/app.component.ts(6,14): error TS2304: Cannot find name 'BrowserModule'.

I'm currently stuck on resolving the issue with NgModule recognition. Any guidance on how to proceed would be greatly appreciated.

Answer №1

The issue of receiving the error message, Cannot find name 'NgModule', can be resolved by ensuring that NgModule is imported from @angular/core. Simply adding this import statement to the first line of code will fix the problem.

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

core.js:15723 ERROR TypeError: Unable to access the 'OBJECT' property because it is undefined

Whenever I attempt to run this function, I encounter an issue. My goal is to retrieve the latitude and longitude of an address from Google's API. This error message pops up: core.js:15723 ERROR TypeError: Cannot read property 'geometry' of ...

Troubleshooting node and npm Installation on a MacBook Air 2018

Upon completing the installer download and following the installation steps found at https://nodejs.org/en/download I encountered an error message when attempting to run node -v: dyld[2548]: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.68.dyli ...

Exploring the use of MockBackend to test a function that subsequently invokes the .map method

I've been working on writing unit tests for my service that deals with making Http requests. The service I have returns a Http.get() request followed by a .map() function. However, I'm facing issues with getting my mocked backend to respond in a ...

Assign the element to either interface A or interface B as its type

Is there a way to assign a variable to be of type interface A OR interface B? interface A { foo: string } interface B { bar: string } const myVar: A | B = {bar: 'value'} // Error - property 'foo' is missing in type '{ bar: s ...

Having trouble starting the server? [Trying to launch a basic HTML application using npm install -g serve]

I am in the process of creating a PWA, but I haven't reached that stage yet. Currently, I have only created an index.html file and an empty app.js. To serve my project locally, I installed serve globally using npm install -g serve When I run the co ...

Why does gulp attempt to import scss libraries that have been deleted from my project?

Currently, I am working on a website where gulp is set up to compile scss and launch a dev server. Unfortunately, I did not set up the project myself and the person who did is unavailable for direct inquiries. Initially, everything was running smoothly. H ...

Querying data elements using Graphql mutations: a step-by-step guide

const MUTATION_QUERY = gql` mutation MUTATION_QUERY( $name: bigint! ) { insert_name( objects: { name: $name } ) { returning { id name } } } `; const [onClick, { error, data }] = useMut ...

This element is not suitable for use as a JSX component since its return type 'void' is not a valid JSX element. Please check the return type to ensure it is compatible with

I have been working on this code snippet: function searchData(searchWord: any) { if (originalData.length > 0) { if (searchWord !== "") { setDataList([...originalData.filter((svc: any) => ...

Error with Firebase authentication on a Next.js project using TypeScript

I recently started a personal project using Next.js, Typescript, and Firebase for authentication and database management. While working on a sign-in page with Google integration, I encountered an error labeled as auth/argument-error. According to the Fireb ...

How to resolve the issue of not being able to access functions from inside the timer target function in TypeScript's

I've been attempting to invoke a function from within a timed function called by setInterval(). Here's the snippet of my code: export class SmileyDirective { FillGraphValues() { console.log("The FillGraphValues function works as expect ...

Building a Search Object using Template String Types

Here is a type definition that allows for specific responses: type Response = 'n_a' | 'n_o' | 'yes' | 'no' I want to create a type that ensures underscores are replaced with slashes: type ReplaceUnderscoreWithSlash& ...

The unit tests are not triggering the execution of setTimeout

Currently, I am developing a project in TypeScript and for unit-tests, I am utilizing QUnit and sinonjs. One of the functions within my code dynamically renders UI elements. I need to retrieve the width of these dynamic elements in order to perform additio ...

The installation of vue-cli using npm has been successfully completed and now supports coffeescript integration

After numerous attempts to set it up using various versions of nodejs / npm and multiple hosts, I even tried installing it on a docker image: Sending build context to Docker daemon 2.048kB Step 1/4 : FROM node:slim ---> c4e99b1ed64f Step 2/4 : RUN np ...

"Why is it that the onChange method of the antd table does not return an array of numbers for selectedRowKeys

In my current project, I am working on a Nextjs application that utilizes typescript and antd. The application includes a table component from antd which allows users to select rows. const rowSelection = { onChange: (selectedKeys: any[], selectedRows: M ...

Building Angular CLI Applications with Separate SCSS Files for Browser Loading

Below is how I am importing the scss file: import { Component, OnInit, ViewEncapsulation } from '@angular/core'; @Component({ ...., styleUrls: ['../../scss/dashboard_admin.scss'], encapsulation: ViewEncapsulation.None }) e ...

Excess whitespace found in string within mat-option

Every time I retrieve text from the mat-option, I notice an additional space at the end of the string. This causes my assertion to fail when trying to compare it with the expected value. This issue is new to me, and I'm unsure how to address it. Why ...

Encountering an error while attempting to install expo-cli globally using npm install

I'm experiencing difficulties with the installation of expo-cli. How can I resolve this error? You can refer to the image provided below for assistance. UPDATE: I have included the error logs from my notepad Raw JSON explanation object: For a detailed ...

Re-enable VueJS Devtools during the development process

While working in my homestead development environment, I decided to run the command npm run production to test if the vuejs devtools would disappear and make sure everything was functioning properly. Surprisingly, the devtools did vanish. Now, I am struggl ...

HTTP POST request is being blocked due to cross-origin request

My angular client app is sending http requests to a .NET core web API, but I'm encountering a CORS error even though I have enabled CORS. Interestingly, GET requests to my SearchController work fine without any issues, but when it comes to sending a P ...

Angular: Step-by-step guide to controlling input field visibility with a toggle switch

// The property autoGenerate is declared in my .ts file autoGenerate: boolean; constructor(){ this.autoGenerate = true; } <div class="col-sm-4"> <div class="checkbox switcher"> <label>Invoice Number * <input t ...