Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR in node_modules/@types/node/globals.global.d.ts(1,44): error TS2304: Cannot find name 'globalThis'

I am using angular 7.2.6, angular-cli 7.3.9 and typescript 3.2.4. I am getting error when building angular app ERROR in node_modules/@types/node/globals.global.d.ts(1,44): error TS2304: Cannot find name 'globalThis'. Can someone please let me know the probable cause for this error.

I see globalThis is introduced in typescript 3.4; but considering i am using typescript 3.2.4, not sure what is causing the above, and how globalThis module is being referred to access variables.

like image 901
vrreddy1234 Avatar asked Jan 15 '21 08:01

vrreddy1234


People also ask

How to solve the error 'cannot find module 'TS-node/Register' in NPM?

To solve the error "Cannot find module 'ts-node/register'", install ts-node and typescript as development dependencies by running npm install --save-dev ts-node typescript. Open your terminal in your project's root directory (where your package.json file is located) and run the following command:

What is the type of global variable in @types/node?

@types/node": "14.0.5" - Variable 'global' must be of type 'Global', but here has type 'Global & typeof globalThis'. · Issue #45116 · DefinitelyTyped/DefinitelyTyped · GitHub

Is it possible to use typescript's type guards to check for node errors?

It was possible to use TypeScript's type guards to create a function that I could use to check the error at runtime, so that I (and TypeScript) could be absolutely sure that this variable was a Node Error. The example function from StackOverflow looked sort of like this:

Is there a typeguarded version of instanceof for Node JS error handling?

It turned out that the key was to make a generic function which acted as a typeguarded version of instanceof for Node.JS error handling, by doing the following things: Accepted two arguments that would be similar to the left-hand and right-hand sides of the instanceof operator.


3 Answers

Thanks Vishal Kedar for your response. Your response helped me to think and explore further. After i changed "@types/node": "10.14.0", the issue is resolved.

like image 138
vrreddy1234 Avatar answered Oct 19 '22 05:10

vrreddy1234


Update the package.json file for the below module

"@types/node": "^14.0.4"
like image 41
Vishal Kedar Avatar answered Oct 19 '22 05:10

Vishal Kedar


Yes! as @vishal said:

npm install @types/[email protected] --saveDev

works perfectly for me too

Thanks!

like image 31
Mayur Saner Avatar answered Oct 19 '22 05:10

Mayur Saner