react-date-range icon indicating copy to clipboard operation
react-date-range copied to clipboard

(0 , _dateFns.addYears) is not a function

Open anushka-2022 opened this issue 9 months ago • 2 comments
trafficstars

ERROR (0 , _dateFns.addYears) is not a function TypeError: (0 , _dateFns.addYears) is not a function at ./node_modules/react-date-range/dist/components/Calendar/index.js (http://localhost:3000/static/js/vendors-node_modules_react-date-range_dist_index_js-node_modules_date-fns_addDays_js.chunk.js:660:34) at options.factory (http://localhost:3000/static/js/bundle.js:72242:31) at webpack_require (http://localhost:3000/static/js/bundle.js:71630:32) at fn (http://localhost:3000/static/js/bundle.js:71901:21) at ./node_modules/react-date-range/dist/components/DateRange/index.js (http://localhost:3000/static/js/vendors-node_modules_react-date-range_dist_index_js-node_modules_date-fns_addDays_js.chunk.js:1052:40) at options.factory (http://localhost:3000/static/js/bundle.js:72242:31) at webpack_require (http://localhost:3000/static/js/bundle.js:71630:32) at fn (http://localhost:3000/static/js/bundle.js:71901:21) at ./node_modules/react-date-range/dist/index.js (http://localhost:3000/static/js/vendors-node_modules_react-date-range_dist_index_js-node_modules_date-fns_addDays_js.chunk.js:2316:41) at options.factory (http://localhost:3000/static/js/bundle.js:72242:31)

anushka-2022 avatar Feb 10 '25 06:02 anushka-2022

+1

kishanDoshi8 avatar Feb 10 '25 16:02 kishanDoshi8

This happens because create-react-app doesn't support *.cjs files. So require('date-fns') returns a string (more specifically, a URL to a *.cjs file), instead of a JS module object. Hence the error.

See https://github.com/facebook/create-react-app/issues/12700 for a possible solution.

xemlock avatar Mar 03 '25 09:03 xemlock