Skip to content

TypeError: MercadoPago is not a constructor #278

Closed Answered by lucmkz
fof3096 asked this question in Q&A
Discussion options

You must be logged in to vote

Good afternoon @fof3096!
There really was an innocence to the examples added on github, for vanilla javascript integration.
To create your integration correctly with javascript, it is necessary to add the .default at the end of MercadoPago
Eg.

import MercadoPago from 'MercadoPago'
...
const client = new MercadoPago.default({
  accessToken: process.env.MERCADO_PAGO_ACCESS_TOKEN,
});

This happens because the bundle is built and delivered using commonjs.

Or to import in a named way, you must use the module is called MercadoPagoConfig
Eg.

import { MercadoPagoConfig } from 'MercadoPago'
...
const client = new MercadoPagoConfig({
  accessToken: process.env.MERCADO_PAGO_ACCESS_TOKEN,
});

This wa…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@fof3096
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by lucmkz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants