nollup: if (module) { } can cause a potential error.
can cause Error: โmoduleโ is not defined
https://github.com/PepsRyuu/nollup/blob/master/docs/hmr.md
if (import.meta.module) {
module.hot.accept(() => {
window.location.reload();
});
}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta
sorry for my poor English.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (7 by maintainers)
Weโve all been there! Even experienced engineers I teach make the same mistake occasionally. Iโve have worked with many senior engineers over the years who struggle to configure Webpack. Wanting to understand how bundlers worked was one of the reasons I started this project. ๐ If you ever get the chance, I highly recommend challenging yourself to write your own very basic bundler. Itโs one of my favourite exercises I like to give to any student of mine. ๐
I see. Thank you very much for your help.
Even when I usually write differenct codes, I have a hard time separating the context(node/compiled) of JavaScript as needed.
I hope this will be a lesson for me. haha ๐
From the looks of it, you just need to use something to remove the
module
code. Usually themodule.hot
logic is handled by a third-party plugin that automatically inserts it and removes it in production. You have a few options here.@rollup/plugin-terser
to remove the code.You can see this in the documentation here: https://github.com/PepsRyuu/nollup/blob/master/docs/hmr.md#additional-build-configuration-for-hmr
Personally I would choose the second option, as it prevents your code from containing bundler specific logic. ๐
Ah the error is in the compiled code. Gotcha. Having a look into it!