Skip to content
Advertisement

Angular Material (8) S2591: Cannot find name ‘require’

I am trying to log date/time into the javascript console. The error message I am getting is as follows and was generated by the code below.

ETA: the code does work. The dates are going to the console. It is just the Error Message remains

Message:

ERROR in src/app/kdc/services/customers.api.service.ts(60,9): error TS2591: Cannot find name ‘require’. Do you need to install type definitions for node? Try npm i @types/node and then add node to the types field in your tsconfig.

NOTE: I have already made changes to the tsconfig.json file and have also done npm i @types/node and npm i @types/node --save When running npm result was 3 high-security vulnerabilities (see below)

enter image description here

What can I do at this point?`

customer.api.service.ts

JavaScript

ETA I found the message here Cannot find name ‘require’ after upgrading to Angular4 and made the change to my tsconfig.app.json file – it may be overkill, but it worked …

JavaScript

Advertisement

Answer

Make sure you put the type in your tsconfig.app.json not your tsconfig.json

JavaScript

Also make sure your systax in your component look like this

JavaScript

Then stop angular cli then run again

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement