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?
isMaster
is not a named import of the the cluster
module. It's a property of the default export of the module.
This means that you want to import the default export, and not as import * as
.
import cluster from "cluster"
if (cluster.isMaster) { console.log('master') }
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.