Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: _dateFns.addYears is not a function #664

Open
iTs-Mantrin opened this issue Feb 18, 2025 · 1 comment
Open

Uncaught TypeError: _dateFns.addYears is not a function #664

iTs-Mantrin opened this issue Feb 18, 2025 · 1 comment

Comments

@iTs-Mantrin
Copy link

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

@xemlock
Copy link

xemlock commented Mar 3, 2025

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 facebook/create-react-app#12700 for a possible solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants