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

Viewed 11349

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?

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

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

It could be connected with eslint in create-react-app

try to reinstall 'eslint' or 'eslint-config-react-app' https://github.com/AtomLinter/linter-eslint/issues/1351

BaseConfig is a variable of the create-react-app react-scripts module in node_modules/react-scripts/config/webpack.config.js


  formatter: require.resolve('react-dev-utils/eslintFormatter'),
                eslintPath: require.resolve('eslint'),
                resolvePluginsRelativeTo: __dirname,
                // @remove-on-eject-begin
                ignore: isExtendingEslintConfig,
                baseConfig: isExtendingEslintConfig
                  ? undefined
                  : {
                      extends: [require.resolve('eslint-config-react-app')],

For me, downgrade the react-scripts to latest 3.x version solved my problem. I could not update the NodeJS version, as I didn't have access to NodeJS server instance. Seems it fits better with React 16.x.

I'm running and building the app at NodeJS V10.0.0.

I am a noob, but I just came across this very same error message in picking up where I previously had left off following a MERN stack tutorial. During the break, I must have switched nvm versions, and thanks to this thread I was able to correct this. From the terminal, I simply ran nvm list. From the result, I could see that I was running an older version (10.9.0) but had a newer one (10.12.0) available to me, which I switched to by running nvm use 10.12.0. This resolved my issue.

Related