Detect module format on demand, instead of relying on module.format, since module.format is undefined in production build.