DEV Community

Declan Middleton
Declan Middleton

Posted on

SyntaxError: The requested module 'react' is expected to be of type CommonJS

I've had this issue countless times during the processes of running the dev environment

Downgrading the nodejs version to 12.22.0 removes the error.

Top comments (4)

Collapse
 
joelbonetr profile image
JoelBonetR πŸ₯‡ • Edited

Noo don't do that! 😱 Running outdated versions is always harmful in a way or another check this

Use always the latest LTS (Long Term Support) which is the production, stable version (this is applied to any software).

Instead of getting the "latest" which at the time of writting that is the experimental 18.7.0, use the 16.16.0 LTS.

You can use NVM (Node Version Manager) to handle that easily:

nvm install --lts // installs the latest Node LTS version
nvm ls // list installed versions of Node
nvm use 16.16.0 // make that specific version the default one for your runtime

Check it and come back to add some feedback and see if the latest LTS worked as well (it'll probably do) and add more information if it doesn't (dependencies, dev dependencies, OS...)

Also you can add the tag #help

Best regards

Collapse
 
declanmidd profile image
Declan Middleton

Yes, I've agreed to these use cases, using this as an option because other packages still require 12.22.0

Regards

Collapse
 
joelbonetr profile image
JoelBonetR πŸ₯‡

And why don't you update those packages as well? πŸ˜…

Updating project dependencies is a recurring task (once a week, once a month...) to fix possible vulnerabilities and not something you do by fashion.

Thread Thread
 
declanmidd profile image
Declan Middleton

Sorry for the "mis reply"

Like I said before "I've agreed to these use cases". The known packages that I've been using require 12.22.0 node version for compatibility using their library. I don't agree with it, I have to integrate it otherwise.