Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

739
Views
ReferenceError: XMLHttpRequest is not defined in emailjs

I'm trying to use emailjs to send email to user after submission of form but I'm getting this error:

FAILED... ReferenceError: XMLHttpRequest is not defined
    at C:\Users\Awesome\Desktop\Awesome\Websites\Client Websites\alumates-landing-page\node_modules\emailjs-com\cjs\api\sendPost.js:8:21     
    at new Promise (<anonymous>)
    at Object.sendPost (C:\Users\Awesome\Desktop\Awesome\Websites\Client Websites\alumates-landing-page\node_modules\emailjs-com\cjs\api\sendPost.js:7:12)
    at Object.send (C:\Users\Awesome\Desktop\Awesome\Websites\Client Websites\alumates-landing-page\node_modules\emailjs-com\cjs\methods\send\send.js:25:23)
    at C:\Users\Awesome\Desktop\Awesome\Websites\Client Websites\alumates-landing-page\routes\index.js:197:11
    at Layer.handle [as handle_request] (C:\Users\Awesome\Desktop\Awesome\Websites\Client Websites\alumates-landing-page\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\Awesome\Desktop\Awesome\Websites\Client Websites\alumates-landing-page\node_modules\express\lib\router\route.js:137:13)    at Route.dispatch (C:\Users\Awesome\Desktop\Awesome\Websites\Client Websites\alumates-landing-page\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\Awesome\Desktop\Awesome\Websites\Client Websites\alumates-landing-page\node_modules\express\lib\router\layer.js:95:\lib\router\layer.js:95:5)
    at C:\Users\Awesome\Desktop\Awesome\Websites\Client Websites\alumates-landing-page\node_modules\express\lib\router\index.js:281:22

According to the error, the XMLHttpRequest is not defined in emailjs's sendpost.js

I did not modify this file. I just installed emailjs the regular way using

npm install emailjs-com --save

Please, anybody know how to fix? This is my route:

router.post('/groups/join', function (req, res) {

//handle form submission here

var templateParams = {
    url: url,
    group_name: group_name, //gotten from form submission value
    user_name: joinRequest.user_name, //gotten from form submission value
    email: joinRequest.email //gotten from form submission value
  }

  emailjs.send(serviceID, groupID, templateParams)
    .then(function (response) {
      console.log('SUCCESS!', response.status, response.text);
      res.redirect("/login")
    }, function (error) {
      console.log('FAILED...', error);
    });

})

I have also required emailjs and xhr at the top of my route:

var xhr = require("xhr");
var emailjs = require("emailjs-com");
emailjs.init("user_CPxhncQgw2s5e4nNwbu36")
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You have to move the emailjs.send method to front-end. I even installed xhr2 and replaced the code in the module. I got a log saying emailjs does not work on non-browser applications.

about 4 years ago · Juan Pablo Isaza Report

0

For using XHR in node js you need to use an external library like xhr2 First, install it

 npm install xhr2

Now, require it

 var XMLHttpRequest = require('xhr2');
 var xhr = new XMLHttpRequest();
about 4 years ago · Juan Pablo Isaza Report

0

None of this makes any sense. Email.js targets browsers and their APIs. Importing xhr at the top makes no difference; it does not make XHR APIs available in the global scope of Node.

If you REALLY wanted to use it you would need to stub the XHR implementation by using the xhr package to create the skeleton, but it is really the wrong way to go. Just find an email lib targeting Node to begin with.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!