Skip to content
Advertisement

How to use date-fns in a Node.js project?

I installed date-fns as per the following instruction on https://www.npmjs.com/package/date-fns

JavaScript

After that my package.json is updated with the following entry:

JavaScript

Then, I wrote the following code from https://date-fns.org/ and it resulted in error:

JavaScript

Error:

JavaScript

node -v:

JavaScript

enter image description here

Advertisement

Answer

I managed to run it successfully by using require as shown below:

JavaScript

Update:

I installed node v16.6.1 following the instructions in this answer and now I can run the following code successfully:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement