hohaha
hohaha

Reputation: 488

ERROR in Module.createRequire is not a function

I tried to create react app with node version 12.1.0 but it warned me that my minimum node version should be at least 14.0. I used nvm to change my node version to 14.0 and created react app. However, I want to use my app on node version 12.1.0. So I changed to node version v12.1.0 but I got:

"ERROR in Module.createRequire is not a function" error. Also " ERROR in Error: Child compilation failed: Module.createRequire is not a function "

Upvotes: 34

Views: 58012

Answers (7)

Mohammad Hassani
Mohammad Hassani

Reputation: 39

Now node 19.x is released and the 18.x is the recommended version if you want to upgrade your node version, simply you can change this line

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -

to

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

and

curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash -

for latest version

Upvotes: 0

Luigi Morel
Luigi Morel

Reputation: 91

I encountered this while using Eslint. Upon running, npm run lint, the error appeared. I have various Node versions on my dev machine and I noticed that I had run the command using v10.

When I switched to v16, the command worked.

Cause of the error:

Using incompatible Node versions.

Solution

Change Node.js versions (I use Node Version Manager - nvm to do this).

Upvotes: 4

cobberboy
cobberboy

Reputation: 6225

I got this error with an app created with create-react-app v5.0.0, when I was using node v16 (via nvm). Downgrading the project to node 14.18.12 fixed the issue for me (I also deleted node_modules and ran npm install again).

Upvotes: 5

Juno Sprite
Juno Sprite

Reputation: 655

Try completely updating the newest, stable version of both nodejs and npm:

sudo apt -y update && sudo apt -y upgrade

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

sudo apt -y update && sudo apt -y upgrade
sudo apt -y autoremove

Then, change directories into your app directory:

cd myapp/ #Change this to match your app directory

Remove node_modules folder

sudo rm -rf node_modules/

Then reinstall the packages:

npm i

See if your app builds successfully:

npm run build

Upvotes: 9

Daniel Coll Ramirez
Daniel Coll Ramirez

Reputation: 1

You can try

curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -

sudo apt-get install -y nodejs

https://github.com/nodesource/distributions/blob/master/README.md#debinstall

Upvotes: -2

Manohar Seervi
Manohar Seervi

Reputation: 99

Use 14+ of node.js version just use nvm -version_name

Upvotes: 10

MarioG8
MarioG8

Reputation: 5951

As we can read in official docs:

Create React App

Create React App is a comfortable environment for learning React, and is the best way to start building a new single-page application in React.

It sets up your development environment so that you can use the latest JavaScript features, provides a nice developer experience, and optimizes your app for production. You’ll need to have Node >= 14.0.0 and npm >= 5.6 on your machine.

So these are requirements that you must meet and it seems that it cannot be avoided that way .

Upvotes: 40

Related Questions