Daniel Daniel - 1 year ago 574
Javascript Question

Axios with node.js - ReferenceError: XMLHttpRequest is not defined

I'm firing a

request from a simply configured

var Axios = axios.create({
baseURL: myBaseUrl,
headers: {'content-type': 'application/json'}


And been getting the following error:

ReferenceError: XMLHttpRequest is not defined
at dispatchXhrRequest (C:\...\node_modules\axios\dist\axios.js:804:24)
at xhrAdapter (C:\...\node_modules\axios\dist\axios.js:796:11)
at process._tickCallback (internal/process/next_tick.js:103:7)
at Function.Module.runMain (module.js:577:11)
at startup (node.js:160:18)
at node.js:456:3

To my understanding (and according to the docs), axios should work on both web browsers and node.js.

What am i missing?


node - 6.2.1
axios - 0.13.1

Answer Source

It looks like you are requiring a browser-side file and this line node_modules\axios\dist\axios.js confirms it.

It should be node_modules/axios/lib/axios.js