Cannot serialize top-level function called `module` in CommonJS file
overlookmotel opened this issue · 0 comments
overlookmotel commented
Input:
// CommonJS
function module() {}
exports.x = module;
Output:
export default {x: {exports: void 0}};
The reason is that instrumentation passes module
to Livepack's init
function, and it adds it to globals
as a module object.
This problem only applies to function declarations because they're hoisted to top of scope. const module
, let module
and class module
would all be syntax errors, and var module
would still leave the value of module
unchanged at start of the file.
Could try to modify the source to prevent this, but probably better to patch Module.prototype.load
to capture the module object there.