HMR not Working correctly
I am using the
@sapphire/plugin-hmr
Plugin to reload my bot on code changes without relogging to discord.
When I change the text in an embed for example and hmr reloads my changes, they are displayed correctly in discord with the new text.
If you change console logs, add container.logger.info(xyz)
or edit helper files, the changes there are not reflected correctly with the latest changes.
If I want to see the changes I have to stop the dev process and restart the bot completely.
Is this wanted behavior or am I doing something wrong?Solution:Jump to solution
This is expected behavior. @sapphire/plugin-hmr only handles "piece" files (commands, listeners, preconditions, etc)
6 Replies
Probably use the watch script like
tsc --watch yourfile.js
I run npm run dev.
npm run dev
runs run-p watch start
watch
= tsc -w
start
= node dist/index.js
Solution
This is expected behavior. @sapphire/plugin-hmr only handles "piece" files (commands, listeners, preconditions, etc)
What you might be able to do is change and save a helper file, and then change and save a command file that uses it. This forces the command to reload, which would reimport the helper file with the new changes
I'm not sure if that works but it would be worth a try
tried and its not working :(
an option to reload on all file changes would be dope tbh
that won't really be added because there is no good way to reload files in a running process anyway
in CJS there is require cache, and in ESM you can add query params to imports but both are very so/so
You can add it to your own bot or make your own plugin, but we won't be adding it