Module.createRequire is not a function

Anayo Debugging 2

This is one simpler issue, but the simplest bug can be the biggest at times, so I made sure I document it and can help anyone out there too.

Bug

In my react project’s root I have a GitLab-ci.yml file that automatically ru…


This content originally appeared on DEV Community and was authored by Anayo Oleru

Anayo Debugging 2

This is one simpler issue, but the simplest bug can be the biggest at times, so I made sure I document it and can help anyone out there too.

Bug

In my react project's root I have a GitLab-ci.yml file that automatically runs whenever I push a commit to the server. It triggers a notification to the runner I specified, and then it processes the series of tasks I specified.

Which involves building and deploying.

This is a legacy React project, and had long been updated. After upgrading the packages I git committed. Build built successfully but deployment failed. With the following error:

Image description

Solution

I read through the error to understand what the problem really was, and I found it:

Module.createRequire is not a function

That was the only error that was reasonably clear indeed and meant something.

So I Googled it, and I found out that it's an issue with Create React App, it's always on or looking for the latest, which means the Node engine version has to always be the latest and that includes my npm version, else some things might break.

So in essence whatever machine running that project has to have Node >= 14.0.0 and npm >= 5.6

Fix

  1. My GitLab-ci.yml contains a Docker image with a node version of 10.15.3, so there is a need to upgrade.
image: giona69/node-10.15.3-aws-eb
  1. And I temporarily replaced the docker image with the latest node.
image: node:14.18.2
  1. Rebuilt Node-Sass

I added
npm rebuild node-sass
to the deploy script

And Voila!! That fixed the issue. These weeks has been simple, this is the issues I have been experiencing.

My name is Anayo Oleru, I specialise in Backend Development(NodeJS & ExpressJS), but I am experienced with Web frontend(ReactJS) and mobile(React-native). And I am open to offers in these fields.

You can follow me on Twitter at @anayooleru or send an email to: anayo_oleru@outlook.com

Cheers and take care.


This content originally appeared on DEV Community and was authored by Anayo Oleru


Print Share Comment Cite Upload Translate Updates
APA

Anayo Oleru | Sciencx (2021-12-31T22:07:07+00:00) Module.createRequire is not a function. Retrieved from https://www.scien.cx/2021/12/31/module-createrequire-is-not-a-function/

MLA
" » Module.createRequire is not a function." Anayo Oleru | Sciencx - Friday December 31, 2021, https://www.scien.cx/2021/12/31/module-createrequire-is-not-a-function/
HARVARD
Anayo Oleru | Sciencx Friday December 31, 2021 » Module.createRequire is not a function., viewed ,<https://www.scien.cx/2021/12/31/module-createrequire-is-not-a-function/>
VANCOUVER
Anayo Oleru | Sciencx - » Module.createRequire is not a function. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/31/module-createrequire-is-not-a-function/
CHICAGO
" » Module.createRequire is not a function." Anayo Oleru | Sciencx - Accessed . https://www.scien.cx/2021/12/31/module-createrequire-is-not-a-function/
IEEE
" » Module.createRequire is not a function." Anayo Oleru | Sciencx [Online]. Available: https://www.scien.cx/2021/12/31/module-createrequire-is-not-a-function/. [Accessed: ]
rf:citation
» Module.createRequire is not a function | Anayo Oleru | Sciencx | https://www.scien.cx/2021/12/31/module-createrequire-is-not-a-function/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.