Search code examples
reactjsnpmcreate-react-app

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?


Solution

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