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

Subsequent variables declarations must have the same type #68379

Closed
juaal12 opened this issue Jan 30, 2024 · 13 comments
Closed

Subsequent variables declarations must have the same type #68379

juaal12 opened this issue Jan 30, 2024 · 13 comments

Comments

@juaal12
Copy link

juaal12 commented Jan 30, 2024

Hi,

I am facing an issue when trying to build an angular package. It seems that "crypto" variable is declared several times with different "Crypto" types. I have been digging a bit and it seems crypto is declared globally at @types/node/ts4.8/crypto.d.ts:4477:13 and also at typescript/lib/lib.dom.d.ts:18084:13 dropping this an error when trying to build.

DevOps pipeline message:

image

I am using Nuke build and my package is being generated from a TS client generated by NSwag.

var crypto: webcrypto.Crypto;

@kanadgodse-lh
Copy link

Having the same issue and the build is failing in GitLab CI/CD via Docker.
nodejs version: 14.21.1
Angular version: 14.3.0:

Here's a snippet of the build log

#4 0.437 > node pre-build-prod.js && ng build
#4 0.437 
#4 0.504 The environment.prod.ts file was saved!
#4 0.506 The environment.ts file was saved!
#4 0.506 The firebase-messaging-sw.js file was saved!
#4 0.507 The manifest.json file was saved!
#4 3.726 - Generating browser application bundles (phase: setup)...
#4 6.857 - @sentry/angular [es2015/esm2015] (git://github.com/getsentry/sentry-javascript.git)
#4 214.2 ✔ Browser application bundle generation complete.
#4 220.1 ✔ Browser application bundle generation complete.
#4 220.1 
#4 220.1 Warning: /app/node_modules/ngx-intl-tel-input/fesm2020/ngx-intl-tel-input.mjs depends on 'google-libphonenumber'. CommonJS or AMD dependencies can cause optimization bailouts.
#4 220.1 For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
#4 220.1 
#4 220.1 
#4 220.1 
#4 220.1 Error: node_modules/@types/node/ts4.8/crypto.d.ts:4477:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'crypto' must be of type 'Crypto', but here has type 'Crypto'.
#4 220.1 
#4 220.1 4477         var crypto: webcrypto.Crypto;
#4 220.1                  ~~~~~~
#4 220.1 
#4 220.1   node_modules/typescript/lib/lib.dom.d.ts:18084:13
#4 220.1     18084 declare var crypto: Crypto;
#4 220.1                       ~~~~~~
#4 220.1     'crypto' was also declared here.
#4 220.1 
#4 220.1 
#4 220.1 
#4 220.5 npm ERR! code ELIFECYCLE
#4 220.5 npm ERR! errno 1
#4 220.5 npm ERR! clickit@0.0.0 build-prod: `node pre-build-prod.js && ng build`
#4 220.5 npm ERR! Exit status 1

@juaal12
Copy link
Author

juaal12 commented Jan 30, 2024

The bug was introduced in this commit (file ts4.8/crypto.d.ts) 75fea78 .

@girirajawari1
Copy link

same issue coming for me.. how to solve this?

@juaal12
Copy link
Author

juaal12 commented Jan 30, 2024

@girirajawari1

In my case, since I am using Nuke build, I added a new step which after creating a new angular project using ng new my-workspace --no-create-application executes npm package npm install --save-dev @types/node@20.11.5.
This is a workaround that works for me. Downgrading the package version from 20.11.10 to 20.11.5 worked for me but I do not know if it will work for you since I do not know your application/environment needs.

But I would like to have a better and official solution 😅.

@codershiba
Copy link
Contributor

Will be fixed in #68371

@ymombrun
Copy link

Temporary workaround for me, was to use resolutions on package.json to force downgrading to version 20.11.7 (the one that was resolved at last sucessful build for my app)

...
"resolutions": {
     "**/@types/node" : "20.11.7"
},
...

@sterichards
Copy link

Temporary workaround for me, was to use resolutions on package.json to force downgrading to version 20.11.7 (the one that was resolved at last sucessful build for my app)

...
"resolutions": {
     "**/@types/node" : "20.11.7"
},
...

This worked for me

Thank you

@Nadim-Artefact
Copy link

20.11.6 worked for me same error on 20.11.7

@RamMohanSonte
Copy link

RamMohanSonte commented Jan 30, 2024

Both the versions 20.11.7 and 20.11.6 versions did not work out for us

"resolutions": {
"**/@types/node" : "20.11.7"
},

Error is

Error: node_modules/@types/node/ts4.8/crypto.d.ts:4477:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'crypto' must be of type 'Crypto', but here has type 'Crypto'.

4477 var crypto: webcrypto.Crypto;
~~~~~~

node_modules/typescript/lib/lib.dom.d.ts:18084:13
18084 declare var crypto: Crypto;
~~~~~~
'crypto' was also declared here.

@WagaoFC
Copy link

WagaoFC commented Jan 30, 2024

@RamMohanSonte do this in your devDependencies:

"devDependencies": {
"@types/node" : "20.11.7"
}

@jakebailey
Copy link
Member

I just merged a PR which should fix this: #68371

In a half hour when the package is published, please test and let me know if it works.

@kanadgodse-lh
Copy link

I solved it by adding "skipLibCheck": true in tsconfig.json

@WagaoFC
Copy link

WagaoFC commented Feb 1, 2024

@jakebailey thank you very much for the solution. It worked perfectly here.

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

10 participants