wechaty / getting-started

A Starter Project Template for Wechaty works out-of-the-box
https://gitpod.io/#https://github.com/wechaty/wechaty-getting-started
Apache License 2.0
798 stars 351 forks source link

This hot-reload example will not work on the second bot if it is launched asynchronically #71

Open demobo-com opened 5 years ago

demobo-com commented 5 years ago
const { Wechaty } = require('wechaty')

function setupBot(id) {
  const bot = new Wechaty({ profile: `memory-cards/${id}` })
  bot
    .on('scan', './on-scan')
    .start()
  return bot
}

setInterval(async () => {
  setupBot(Math.random())
}, 10000)

We are working on launching bot dynamically. However, whenever we are using hot-reload, any bot launched after the first one will fail. This example will work if we are not using hot-reload.

Error: ERR Wechaty onModulePath(scan, ./on-scan) listener exception: TypeError: Cannot read property 'apply' of undefined

huan commented 5 years ago

Thanks for point out this with code.

I'll look into it when I get time.