I have encountered an issue while working with the mercadopago library. I need to load the mercadopago script file and create an instance of the MercadoPago object. However, nextJS loads the main bundle before including the mercadopago file, resulting in an execution error due to the undefined object.
I experimented with different methods such as loading the script file into the Head component using a normal tag and also utilizing the Next/Script object like so:
<script src="https://sdk.mercadopago.com/js/v2" strategy="beforeInteractive"/>
Despite trying various approaches, Next always ends up loading the script after the main bundle file. Implementing a setTimeout function to wait for the Mercadopago object to be instantiated does work, but it is not an ideal solution. How can I correctly resolve this issue?