Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: "createRequire is not a function Referenced from: BaseConfig"

I have a freshly cloned repo created from the create-react-app template. I npm install to install the packages and then npm start to serve the files on localhost:3000. My coworker (the repo creator) is not having any issues.

However, I see the page flash for a second and then I get the following error:

Failed to compile
createRequire is not a function
Referenced from: BaseConfig

The error message doesn't provide any other information to help trace which file it could be coming from.

I've tried the following to troubleshoot:

  1. Deleting node_modules and package-lock.json and re-installing
  2. Deleting the entire repo and re-cloning
  3. Searching for 'createRequire' or 'BaseConfig' in project files found no results
  4. Searching online for similar issues. None seem to have the same error I'm encountering.

Other details: npm version 6.14.8 react version 17.0.1

Any idea where this error could be coming from or what steps I can do to trace it?

like image 286
Danielle C Avatar asked Nov 14 '20 14:11

Danielle C


2 Answers

TL;DR Needed to upgrade node version

I tried npx create-react-app to confirm if the issue was with the template or with the project code. While doing that, I got a message that my package dependencies required a higher version of node (I was on v.10.4, the latest is v15.2.0).

Doing brew upgrade installed the latest version but didn't change the default node version across the system (ie: node -v still showed v10.4) but doing nvm install --lts then nvm alias-default [latest-version] fixed my issue!

like image 106
Danielle C Avatar answered Nov 12 '22 02:11

Danielle C


Some solutions are not worked for me. I uninstalled node.js and installed latest version. It worked!

like image 30
Hasan Dag Avatar answered Nov 12 '22 01:11

Hasan Dag