Accepted answer

Most probably because you're using d3 v5 which has just been released and most of legacy examples are using d3 v3 or d3 v4.

See Changes in D3 5.0.

The new v5 way of doing is indeed (quoting from the changelog):

d3.json("file.json").then(function(data) {

wherease before it would have been (v3, v4):

d3.json("file.json", function(error, data) {
  if (error) throw error;

Related Query