Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

748
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda