Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
molyviatis opened this issue May 28, 2020 · 19 comments

Comments

@molyviatis
Copy link

I upgraded from Angular 9.17 to 9.19 and now ng build fails with the following error complaining about a variable declaration in both @types/node and zone.js:

ERROR in node_modules/@types/node/ts3.5/globals.global.d.ts:1:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'global' must be of type 'Global', but here has type 'Global & typeof globalThis'.

1 declare var global: NodeJS.Global & typeof globalThis; ~~~~~~

node_modules/zone.js/dist/zone.js.d.ts:600:13 600 declare var global: NodeJS.Global; ~~~~~~ 'global' was also declared here.

When I downgrade @types/node to 14.0.4, everything works. I am using version 0.10.3 of zone.js.

@SimonSchick
Copy link
Contributor

Uh oh, please run npm ls @types/node and post the result.

@molyviatis
Copy link
Author

+-- @angular-devkit/build-angular@0.901.7
| -- license-webpack-plugin@2.1.4 | -- @types/webpack-sources@0.1.7
| -- @types/node@14.0.4 deduped +-- @types/node@14.0.4 -- webpack-dev-server@3.11.0
-- del@4.1.1 -- @types/glob@7.1.1
`-- @types/node@14.0.4 deduped

@SimonSchick
Copy link
Contributor

Oh ok, I see.
Culprit seems to be #44700 @JasonHK

@SimonSchick
Copy link
Contributor

The main issue is that NodeJS.Global & typeof globalThis is a type, not an interface.

@JasonHK
Copy link
Contributor

JasonHK commented May 31, 2020

I've found the line that caused the problem:

https://github.com/angular/angular/blob/d1ea1f4c7f3358b730b0d94e65b00bc28cae279c/packages/zone.js/lib/zone.ts#L678-L682

Although I'm not 100% sure, it seems that this line could be omitted.

@NZhuravlev
Copy link

Those files aren't even supposed to be compiled according to typesVersions for @types/node or am I missing something?

@erlendga
Copy link

erlendga commented Jun 9, 2020

It works if you downgrade to @types/node@13.7

@simonua
Copy link

simonua commented Jun 10, 2020

Hi @erlendga, if you are using NodeJS 14 have you tried 14.0.4? I downgraded from 14.0.13 and found 14.0.4 to work, as also initially suggested by the OP.

@JasonHK
Copy link
Contributor

JasonHK commented Jun 10, 2020

Hi @erlendga, if you are using NodeJS 14 have you tried 14.0.4? I downgraded from 14.0.13 and found 14.0.4 to work, as also initially suggested by the OP.

@simonua I should probably open an issue in angular/angular, since the problem was caused by me.

@simonua
Copy link

simonua commented Jun 10, 2020

@JasonHK, I appreciate the ownership. Thank you.

@tiagolpadua
Copy link

In your tsconfig.app.json you need to add "types": ["node"] too.

@kmaraz
Copy link

kmaraz commented Jul 13, 2020

Hi @JasonHK , can you please provide a link to the issue in Angular so I can subscribe to it? Thank you!

@rezonant
Copy link

angular/angular#37531

@TechieViking
Copy link

I replaced the variable name global with 'some variable name' and replaced all its occurrence in this file /zone.js.d.ts.
declare var global: NodeJS.Global;
This is working as of now for :D

@tafty
Copy link

tafty commented Oct 8, 2020

I have come across this issue in a React Native project. We're using node 12 and have found the error is removed by downgrading to @types/node version 12.12.41. Version 12.12.42 is the first version with this problem for node 12.

@blasco
Copy link

blasco commented Oct 21, 2020

@tafty thanks for sharing, same situation here. The downgrade worked

@samiullahfx
Copy link

@SimonSchick,
When i run this npm ls @types/node, i got the below output.

+-- @angular-devkit/build-angular@0.901.12
| +-- license-webpack-plugin@2.1.4
| | -- @types/webpack-sources@0.1.8 | | -- @types/node@12.19.8 deduped
| +-- terser-webpack-plugin@3.0.3
| | -- jest-worker@26.6.2 | | -- @types/node@12.19.8 deduped
| -- UNMET PEER DEPENDENCY webpack-dev-server@3.11.0 | -- del@4.1.1
| -- @types/glob@7.1.3 | -- @types/node@12.19.8 deduped
+-- @types/node@12.19.8
-- exceljs@4.2.0 -- fast-csv@4.3.5
+-- @fast-csv/format@4.3.5
| -- @types/node@14.14.10 -- @fast-csv/parse@4.3.3
`-- @types/node@14.14.10

npm ERR! peer dep missing: webpack-dev-server@^3.1.4, required by @angular-devkit/build-webpack@0.901.12

@Greenek
Copy link

Greenek commented May 17, 2021

I replaced

const window = domino.createWindow(template);
global['window'] = window;
global['document'] = window.document;

with

const window = domino.createWindow(template);
(global as any).window = window;
(global as any).document = window.document;

and it's working fine with the latest @types/node.

@DollarAkshay
Copy link

@Greenek Using any defeats the point of the having types in the first place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests