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

Uncaught TypeError: _dateFns.addYears is not a function

Open iTs-Mantrin opened this issue 9 months ago • 1 comments
trafficstars

i get the error while using DateRange in react Uncaught runtime errors: ERROR _dateFns.addYears is not a function ./node_modules/react-date-range/dist/components/Calendar/index.js@http://localhost:3000/static/js/bundle.js:27976:34 options.factory@http://localhost:3000/static/js/bundle.js:62455:31 webpack_require@http://localhost:3000/static/js/bundle.js:61907:32 fn@http://localhost:3000/static/js/bundle.js:62114:21 ./node_modules/react-date-range/dist/components/DateRange/index.js@http://localhost:3000/static/js/bundle.js:28263:40 options.factory@http://localhost:3000/static/js/bundle.js:62455:31 webpack_require@http://localhost:3000/static/js/bundle.js:61907:32 fn@http://localhost:3000/static/js/bundle.js:62114:21 ./node_modules/react-date-range/dist/index.js@http://localhost:3000/static/js/bundle.js:29632:41 options.factory@http://localhost:3000/static/js/bundle.js:62455:31 webpack_require@http://localhost:3000/static/js/bundle.js:61907:32 fn@http://localhost:3000/static/js/bundle.js:62114:21 ./src/components/header/Header.jsx@http://localhost:3000/static/js/bundle.js:60871:93 options.factory@http://localhost:3000/static/js/bundle.js:62455:31 webpack_require@http://localhost:3000/static/js/bundle.js:61907:32 fn@http://localhost:3000/static/js/bundle.js:62114:21 ./src/pages/home/Home.jsx@http://localhost:3000/static/js/bundle.js:61572:102 options.factory@http://localhost:3000/static/js/bundle.js:62455:31 webpack_require@http://localhost:3000/static/js/bundle.js:61907:32 fn@http://localhost:3000/static/js/bundle.js:62114:21 ./src/App.js@http://localhost:3000/static/js/bundle.js:60755:93 options.factory@http://localhost:3000/static/js/bundle.js:62455:31 webpack_require@http://localhost:3000/static/js/bundle.js:61907:32 fn@http://localhost:3000/static/js/bundle.js:62114:21 ./src/index.js@http://localhost:3000/static/js/bundle.js:61501:81 options.factory@http://localhost:3000/static/js/bundle.js:62455:31 webpack_require@http://localhost:3000/static/js/bundle.js:61907:32 @http://localhost:3000/static/js/bundle.js:63034:56 @http://localhost:3000/static/js/bundle.js:63036:12

iTs-Mantrin avatar Feb 18 '25 07:02 iTs-Mantrin

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