Daniel Daniel - 4 months ago 153
Javascript Question

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

I'm firing a

GET
request from a simply configured
axios
instance:

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

Axios.get(url)


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?

Versions:

node - 6.2.1
axios - 0.13.1

Answer

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

Comments