How to solve TypeError: d3.time is undefined? How to solve TypeError: d3.time is undefined? node.js node.js

How to solve TypeError: d3.time is undefined?


You are requiring D3 v4.2.2 that doesn't have a d3.time property any more, which was part of D3 v3. According to the changelog the time formats have been subject to the general namespace flattening and were therefore renamed as follows:

That said, it does recognize the d3 object, wheras the d3.time is undefined. Changing your code to

var timeFormat = d3.timeFormat('%H:%M:%S %L');

should do the trick.


The d3 module is recognized. Every assignment in JS returns nothing, therefore executing the line

var d3 = require('d3');

is bound to return...nothing, hence the undefined in your checking (For making sure, just type var a = 0 in your console, you will also get an undefined response). It looks like the function is not defined in the module, rather then the module not being loaded.

You should check the API of the module, to make sure you are using the right function.

L.E. saving you some trouble, here's the link

https://github.com/d3/d3/blob/master/API.md#time-formats-d3-time-format