huan / hot-import

Hot Module Replacement (HMR) for Node.js
https://npmjs.com/package/hot-import
Apache License 2.0
25 stars 2 forks source link

Not functional under docker container. #16

Open seanjiang86 opened 5 years ago

seanjiang86 commented 5 years ago

Basically two issues: When I use something like:

const configF = await hotImport('config.js')
const config = configF()

like the sample, I am getting an error says configF is not a function.

When I try something like:

 const configF = await hotImport('config.js')
 const config = configF.config;

while the "config.js" has the content like this:

export const config = {
  ......
}

I am able to get the config content. However, when I use this piece of code in an event listener, something is not working. For the first time it executed, every thing works fine, but on the second run of the event, the “configF" becomes underfined and I am getting an error on "configF.config". I am wondering has anyone else experienced such issue and could give me an explain?

huan commented 5 years ago

Can you provide a reproduce-able code with the description in detail so that we can have a look into it?

seanjiang86 commented 5 years ago

Such a quick response:) Actually I am trying your wechaty bot and using your https://github.com/Chatie/wechaty-getting-started The sample I use is in "examples/professional/monster-bot/" The environment I use is your suggested docker image : zixia/wechaty on docker version 18.06.1-ce on win10. I hope this message should be able to suggest my image version: Starting Docker Container for Wechaty v0.23.19 with Node.js v10.13.0 ... There are few other minor issues with the default script in my environment like the "Misc" is underfined that I am still checking. The hot-import issue appears the most weird one for me by now. Anyway, thanks for the wechaty framework you provide. It is a very powerfully tool and hope to work on details of it when I am skilled enough :)

huan commented 5 years ago

Thanks for providing that information.

If you want to make sure the hot-import part is workable, could you try the other example at https://github.com/Chatie/wechaty-getting-started/tree/master/examples/professional/hot-import-bot because that's written by me and it should work without any problem?

The monster-bot is from other contributors: @suntong , so I can not guarantee it compatible with hot-import.

seanjiang86 commented 5 years ago

I got a little confused. I have tried to change some log content in the listeners\on-message.js while the bot is running, but the log content remains the same after the change. When I check with the codes in hot-import-bot, there is no place to explicitly import the ”hot-import". If the "wechaty" is implicitly binding listeners through hot-import, I am worrying the "wecahty" in the published image might not containing this feature.

huan commented 5 years ago

The latest version of published docker image and npm module had all included this feature as well.

https://github.com/Chatie/wechaty-getting-started/blob/ba723342d972f313a8ba6f2e07bbfc0883805075/examples/professional/hot-import-bot/hot-import-bot.js#L37-L42

Please pay attention on the above lines, like .on('message', './listeners/on-message'), the event listener here, is a string instead a function.

Inside Wechaty, if we found you passed a string to a event listener, we will treat it as a import-able js module, and use hot-import to load it.

seanjiang86 commented 5 years ago

I understand your explain and point. The issue is I am not able to see the hot-import working at my environment. After switching the content inside the onMessage file, nothing changed for the robot. I have even tried delete the on-message file and everything still works fine. Both the cnpm(taobao) image and npm image is not working. I will try check whether some default caching mechanism has been enabled for the docker container on win10. Thanks for your explain.

huan commented 5 years ago

Can you try it without docker?

It might be related to the docker container because we have limited privileges inside the docker.

I had run this example under native Linux without any problem before.

P.S. after the handler file is loaded, the node system can work without any problem even you delete the handler file, this is the right behavior.

seanjiang86 commented 5 years ago

Ha, it is fully functional without docker. It is working fine in windows node envirnoment. Will close this issue and try reproducing hot-import issue in event listener seperately. It's up to you to check the container issue, I will also try on a different OS. Thanks for your time!

huan commented 5 years ago

Glad to hear that, and I think we should keep this issue open as a bug with container technology.