SyntaxError: Unexpected token M in JSON at position 0
See original GitHub issueHere the complete error:
SyntaxError: Unexpected token M in JSON at position 0
at JSON.parse (<anonymous>)
at x.json (/workspace/node_modules/mailgun.js/dist/mailgun.js:2:37391)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
This is my code:
import Mailgun from 'mailgun.js';
const MAILGUN_KEY: string = functions.config().mailgun.key;
const MAILGUN_URL: string = functions.config().mailgun.url;
const MAILGUN_DOMAIN: string = functions.config().mailgun.domain;
const mailgun = new Mailgun(require('form-data'));
const mg = mailgun.client({
username: 'api',
key: MAILGUN_KEY,
url: MAILGUN_URL,
});
..........
await mg.messages.create(MAILGUN_DOMAIN, {
to: [to],
from: `****- ****<${from}>`,
bcc: '****@****',
subject,
html,
});
I checked everything in my configuration, I have no problem with sendgrid js api so no network problem.
I am using node 12, "mailgun.js": "^3.3.0",
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Unexpected token m in JSON at position 0 error - Stack Overflow
The reason it says unexpected token m is because the json-loader transforms your json into a javascript file which starts with ...
Read more >What Is JSON and How to Handle an “Unexpected Token” Error
“Unexpected token < in JSON at position 0” is the error that I have seen most throughout my time of working as a...
Read more >How to Fix SyntaxError: Unexpected token < in JSON at ...
This guide will help to fix SyntaxError: Unexpected token < in JSON at position 0 . This guide also applies to these other...
Read more >Unexpected token in JSON at position 0 - Moodle.org
Re: Unexpected token in JSON at position 0 ... This usually means that an error has been returned and that's not valid JSON....
Read more >How To Fix Unexpected token u in JSON at position 0 - Isotropic
The "Unexpected token u in JSON at position 0" is a typically Javascript error that will show up in your console log if...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I see, a simple misconfiguration can bring you this kind of error. I think it should be easier to understand. I will look into the code to make this thing simpler, hope soon.
For anyone looking for an answer: check your configuration.
Oh my god, it’s working! So the documentation is wrong. If you see here https://documentation.mailgun.com/en/latest/quickstart-sending.html#send-via-api and click on Node.js, you can clearly see right under the code example
NOTE: If you’re sending from our EU infrastructure, be sure to substitute our EU endpoint in the above example: https://api.eu.mailgun.net/v3
So that’s what I used and assumed this is correct. Thank you @olexandr-mazepa you’re a star 🙂