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.
Uh oh, please run npm ls @types/node and post the result.
+-- @angular-devkit/[email protected]
| -- [email protected]
|-- @types/[email protected]
| -- @types/[email protected] deduped
+-- @types/[email protected]
-- [email protected]
-- [email protected]
-- @types/[email protected]
`-- @types/[email protected] deduped
Oh ok, I see.
Culprit seems to be https://github.com/DefinitelyTyped/DefinitelyTyped/pull/44700 @JasonHK
The main issue is that NodeJS.Global & typeof globalThis is a type, not an interface.
I've found the line that caused the problem:
Although I'm not 100% sure, it seems that this line could be omitted.
Those files aren't even supposed to be compiled according to typesVersions for @types/node or am I missing something?
It works if you downgrade to @types/[email protected]
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.
Hi @erlendga, if you are using NodeJS 14 have you tried
14.0.4? I downgraded from14.0.13and found14.0.4to 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.
@JasonHK, I appreciate the ownership. Thank you.
In your tsconfig.app.json you need to add "types": ["node"] too.
Hi @JasonHK , can you please provide a link to the issue in Angular so I can subscribe to it? Thank you!
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
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.
@tafty thanks for sharing, same situation here. The downgrade worked
Most helpful comment
It works if you downgrade to @types/[email protected]