Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node js clusters can't be imported in typescript

Tags:

typescript

I'm imported clusters as import * as cluster from "cluster"; and when I'm trying to check cluster.isMaster in if(cluster.isMaster){} I'm getting this error

TS2339: Property 'isMaster' does not exist on type 'typeof import("cluster")'.

and import cluster from "cluster"; I'm getting that cluster is undefined. How can I solve the problem in ts, how can I import clusters in ts and use them?

like image 487
Gevorg Martirosyan Avatar asked Aug 24 '26 06:08

Gevorg Martirosyan


2 Answers

I have got the same issue today, and this workaround worked for me:

import * as _cluster from 'cluster';
const cluster = _cluster as unknown as _cluster.Cluster; // typings fix
like image 102
ndry Avatar answered Aug 26 '26 21:08

ndry


I faced the same issue today and solved it by setting "esModuleInterop": true in tsconfig.json.

like image 25
Dmitry Korolev Avatar answered Aug 26 '26 21:08

Dmitry Korolev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!