d3 / d3-request

A convenient alternative to XMLHttpRequest.
BSD 3-Clause "New" or "Revised" License
110 stars 54 forks source link

XMLHttpRequest is not defined #9

Closed mindrones closed 8 years ago

mindrones commented 8 years ago

Hi, this script:

var d3 = require('d3');
d3.json('https://nodejs.org/api/all.json', function(err, json) {})

returns:

/path/to/node_modules/d3/build/d3.js:4438
          xhr = new XMLHttpRequest,
                    ^
ReferenceError: XMLHttpRequest is not defined
    at request (/path/to/node_modules/d3/build/d3.js:4438:18)
$ node -v; npm -v
v5.7.0
3.6.0
$ npm list
...
+-- d3@4.0.0-alpha.24
| +-- d3-array@0.7.1
| +-- d3-axis@0.3.0
| +-- d3-collection@0.1.2
| +-- d3-color@0.4.2
| +-- d3-dispatch@0.4.2
| +-- d3-dsv@0.3.0
| | `-- rw@1.1.1
| +-- d3-ease@0.7.0
| +-- d3-format@0.5.1
| +-- d3-interpolate@0.7.0
| +-- d3-path@0.1.5
| +-- d3-polygon@0.2.1
| +-- d3-quadtree@0.2.1
| +-- d3-queue@2.0.2
| +-- d3-random@0.2.1
| +-- d3-request@0.4.4
| | `-- xmlhttprequest@1.5.0
| +-- d3-scale@0.6.4
| +-- d3-selection@0.7.0
| +-- d3-shape@0.5.1
| +-- d3-time@0.2.4
| +-- d3-time-format@0.3.1
| +-- d3-timer@0.4.1
| +-- d3-transition@0.2.5
| `-- d3-voronoi@0.3.2
...
mbostock commented 8 years ago

XMLHttpRequest is not defined in Node.js. The d3-request library has a polyfill for it, but that polyfill does not extend to the d3 bundle. I suppose it should, but this issue should be filed in mbostock/d3, not here.

mbostock commented 8 years ago

I’ve fixed this in mbostock/d3#2755. It will be available in the next alpha release, 4.0.0-alpha.25.