my app is one using origin nodejs cluster code inside ,and run by node ./dist/main.js fine but it go wrong when i use pm2 start ./dist/main.js
//my code
import cluster from 'cluster'
import http from 'http'
if(cluster.isMaster){
(async()=>{
const master = await (await import('./master'))
async function onMsg(pid:number,type?:string,num?:number,data?:{db:any,apiName:any,args:Array<any>}){
console.log(`master receiving message from cluster ${pid}`)
try{
let result = await master.publishMission(type,data)
// console.log(`${type} finish mission and send back to koa cluster ${pid}`)
cluster.workers[pid].send({num:num,status:true,data:result})
}catch(err){
cluster.workers[pid].send({num:num,err})
}
}
//cluster nums
for(let i=0;i<1;i++){
cluster.fork()
}
cluster.on('message',(worker,msg)=>{
onMsg(worker.id,...msg)
})
cluster.on('exit', (worker, code, signal) => {
console.log('worker %d died (%s). restarting...',worker.process.pid, signal || code);
cluster.fork();
});
})()
}else{
(async()=>{
const app = await (await import('./app')).app
try{
http.createServer(app).listen(5000)`enter code here`
console.log("fork new koa server",process.pid)
}catch(err){
console.log(err)
}
})()
}
//error log TypeError: Found non-callable @@iterator at EventEmitter. (C:\Users\yany\project\Jmrh_Warehouse\src\main.ts:22:13) at EventEmitter.emit (events.js:315:20) at Worker. (internal/cluster/master.js:174:13) at Worker.emit (events.js:315:20) at ChildProcess. (internal/cluster/worker.js:32:12) at ChildProcess.emit (events.js:315:20) at emit (internal/child_process.js:903:12) at processTicksAndRejections (internal/process/task_queues.js:81:21) TypeError: Found non-callable @@iterator at EventEmitter. (C:\Users\yany\project\Jmrh_Warehouse\src\main.ts:22:13) at EventEmitter.emit (events.js:315:20) at Worker. (internal/cluster/master.js:174:13) at Worker.emit (events.js:315:20) at ChildProcess. (internal/cluster/worker.js:32:12) at ChildProcess.emit (events.js:315:20) at emit (internal/child_process.js:903:12) at processTicksAndRejections (internal/process/task_queues.js:81:21)