react-date-range
react-date-range copied to clipboard
(0 , _dateFns.addYears) is not a function
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)
+1
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.