DEV Community

Cover image for Module.createRequire is not a function
Anayo Samson Oleru
Anayo Samson Oleru

Posted on

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 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


Enter fullscreen mode Exit fullscreen mode

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


Enter fullscreen mode Exit fullscreen mode
  1. And I temporarily replaced the docker image with the latest node.


image: node:14.18.2


Enter fullscreen mode Exit fullscreen mode
  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.

Top comments (0)