Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NextJs import doesn't work for certain libs

I created a Next.Js app with create-next-app and trying to import and use ramda. But it gives me next error TypeError: Cannot read properties of undefined (reading 'add'). So actual import from lib is undefined.

Code snippet
Error with ramda

But if I replace ramda.add with lodash.add – all works fine. Do somebody know what is the difference and how I make it work with ramda?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My setup

"lodash": "^4.17.21",
"next": "13.0.5",
"ramda": "^0.28.0",
"typescript": "4.9.3"

"packageManager": "yarn@3.3.0",

I would expect it work with both libs, as for me there’s no difference in usage.
I tried to move it to getServerSideProps, use yarn v1, npm, recreate a project..

>Solution :

See https://ramdajs.com/ docs:

Note for versions > 0.25 Ramda versions > 0.25 don’t have a default export. So instead of import R from ‘ramda’;, one has to use import * as R from ‘ramda’; Or better yet, import only the required functions via import { functionName } from ‘ramda’;

So you have to use

import * as R from 'ramda';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading