Initialization error eslint module createrequire is not a function

I'm using react app with Parcel bundler & TypeScript. I'm trying to use ESLint but I get this error: ESLint: Initialization error (ESLint). Module.createRequire is not a function. versions: IDE:

I’m using react app with Parcel bundler & TypeScript.
I’m trying to use ESLint but I get this error:

ESLint: Initialization error (ESLint). Module.createRequire is not a function.

versions:

  • IDE: Webstorm
  • Node Version: 16.6.2
  • NPM Version: 7.20.3
  • I don’t have ESLint installed globally in my machine

This is my setup:

package.json:

{
  "name": "app-boilerplate",
  "version": "1.0.0",
  "description": "",
  "source": "public/index.html",
  "scripts": {
    "start": "parcel --port=3000 --open --lazy",
    "build": "parcel build",
    "lint": "eslint . --ext .tsx,.ts",
    "lint:fix": "eslint . --ext .tsx,.ts --fix",
    "test": "jest --coverage --passWithNoTests",
    "test:watch": "jest --watchAll --coverage",
    "prepare": "husky install",
    "storybook": "start-storybook -p 6006",
    "build-storybook": "build-storybook"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.16.7",
    "@parcel/transformer-svg-react": "^2.2.0",
    "@storybook/addon-actions": "^6.4.13",
    "@storybook/addon-essentials": "^6.4.13",
    "@storybook/addon-links": "^6.4.13",
    "@storybook/react": "^6.4.13",
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@types/jest": "^27.4.0",
    "@typescript-eslint/eslint-plugin": "^5.9.1",
    "@typescript-eslint/parser": "^5.9.1",
    "babel-loader": "^8.2.3",
    "eslint": "^8.7.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-import": "^2.25.4",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-react": "^7.28.0",
    "eslint-plugin-react-hooks": "^4.3.0",
    "eslint-plugin-storybook": "^0.5.5",
    "husky": "^7.0.4",
    "jest": "^27.4.7",
    "parcel": "^2.2.0",
    "prettier": "^2.5.1",
    "ts-jest": "^27.1.3",
    "typescript": "^4.5.4"
  },
  "dependencies": {
    "@types/node": "^17.0.8",
    "@types/react": "^17.0.38",
    "@types/react-dom": "^17.0.11",
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
  "alias": {
    "@hooks": "./src/hooks",
    "@libs": "./src/libs"
  }
}

.eslintrc.json:

{
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": [
        "plugin:react/recommended",
        "airbnb",
        "prettier",
        "plugin:storybook/recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "project": "./tsconfig.json",
        "ecmaFeatures": {
            "jsx": true
        },
        "sourceType": "module"
    },
    "plugins": [
        "react",
        "@typescript-eslint",
        "jsx-a11y"
    ],
    "rules": {
        "import/extensions": [2, "never"],
        "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx", ".tsx", ".ts"] }],
        "react/jsx-indent": [2, 2, {"checkAttributes": true, "indentLogicalExpressions": true}],
        "react/react-in-jsx-scope": "off",
        "no-console": "off"
    },
    "settings": {
        "import/resolver": {
            "node": {
                "extensions": [".js", ".jsx", ".ts", ".tsx"]
            }
        }
    }
}

The actual error inside Webstorm
enter image description here

How can I solve it, please?
Thank you.

Whenever I am trying to create a new react app I am facing the following error: Module.createRequire is not a function in ReactJS. We are going to Learn about All Possible Solutions So Lets Get Start with This Article.

Contents

  1. How Module.createRequire is not a function Error Occurs?
  2. How To Solve Module.createRequire is not a function Error?
  3. Solution 1: Use Node >= 14.0.0 and npm >= 5.6
  4. Summary

How Module.createRequire is not a function Error Occurs?

Whenever I am trying to create a new react app I am facing following error:

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

So here I am writing all the possible solutions that I have tried to resolve this error.

How To Solve Module.createRequire is not a function Error?

  1. How To Solve Module.createRequire is not a function Error?

    To Solve Module.createRequire is not a function Error Creating a new react app You’ll must need to have Node >= 14.0.0 and npm >= 5.6 on your machine so Just Install Node’s latest version and Also Update Your NPM. First of all, run this command to update the node: npm install -g npm Now update npm to the latest version by running this command: npm install npm@latest -g And now, your error must be solved. Thanks.

  2. Module.createRequire is not a function

    To Solve Module.createRequire is not a function Error Creating a new react app You’ll must need to have Node >= 14.0.0 and npm >= 5.6 on your machine so Just Install Node’s latest version and Also Update Your NPM. First of all, run this command to update the node: npm install -g npm Now update npm to the latest version by running this command: npm install npm@latest -g And now, your error must be solved. Thanks.

Solution 1: Use Node >= 14.0.0 and npm >= 5.6

Creating a new react app You’ll must need to have Node >= 14.0.0 and npm >= 5.6 on your machine so Just Install Node’s latest version and Also Update Your NPM. First of all, run this command to update the node.

npm install -g npm

Now update npm to the latest version by running this command.

npm install npm@latest -g

And now, your error must be solved. Thanks.

Summary

It’s all About this error. Hope We solved Your error. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

  • npm ERR! code ENOLOCAL npm ERR! Could not install from “@muimaterialutils” as it does not contain a package.json file
  • How to go back to previous route in react-router-dom v6?
  • Error: HTTP Error: 400, Invalid JSON payload received. Unknown name “skipLog”: Cannot find field
  • Matched leaf route at location “/” does not have an element
  • How to downgrade React version 16 to 15?

Hello readers, Today In this article I am going to show you how to Solve – Module.createRequire is not a function Error in ReactJs. So here I will explain all the possible solutions.

Without wasting your time, Let’s start This Article to Solve This Error.

How Module.createRequire is not a function Error Occurs?

This is a common error in Python. When I am trying to create a new react app. but, I am facing following error. It looks as like below:

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

So here are all the possible solutions that I tried to fix this error.

How To Solve Module.createRequire is not a function Error?

  • How To Solve Module.createRequire is not a function Error?

To Solve Module.createRequire is not a function Error Creating a new react app You’ll must need to have Node >= 14.0.0 and npm >= 5.6 on your machine so Just Install Node’s latest version and Also Update Your NPM. First of all, run this command to update the node: npm install -g npm Now update npm to the latest version by running this command: npm install [email protected] -g And now, your errorwill be gone.

  • Module.createRequire is not a function

To Solve Module.createRequire is not a function Error Creating a new react app You’ll must need to have Node >= 14.0.0 and npm >= 5.6 on your machine so Just Install Node’s latest version and Also Update Your NPM. First of all, run this command to update the node: npm install -g npm Now update npm to the latest version by running this command: npm install [email protected] -g And now, your errorwill be gone.

Solution 1: Use Node >= 14.0.0 and npm >= 5.6

You’ll need to have Node >= 14.0.0 and npm >= 5.6 on your machine so Just Install Node’s latest version and Also Update Your NPM. First of all, run this command to update the node.

npm install -g npm

Now update npm to the latest version by running this command.

npm install [email protected] -g

Now, your error will be gone.

Conclusion

In this article, we have discussed what causes the error and we have discussed ways to fix the error.

we hope this article has been informative. Thank you for reading. Kindly comment and let us know if you found it helpful.

Cover image for Module.createRequire is not a function

Anayo Oleru

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.

An Animated Guide to Node.js Event Lop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.

У меня есть только что клонированное репо, созданное из шаблона create-react-app. Я npm install для установки пакетов, а затем npm start для обслуживания файлов на localhost: 3000. У моего коллеги (создателя репо) проблем нет.

Однако я вижу, что страница мигает на секунду, а затем получаю следующую ошибку:

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

Сообщение об ошибке не предоставляет никакой другой информации, чтобы помочь отследить, из какого файла оно могло быть получено.

Я пробовал следующее для устранения неполадок:

  1. Удаление node_modules и package-lock.json и повторная установка
  2. Удаление всего репо и повторное клонирование
  3. Поиск ‘createRequire’ или ‘BaseConfig’ в файлах проекта не дал результатов
  4. Ищу в Интернете похожие проблемы. Кажется, ни у кого нет такой же ошибки, с которой я сталкиваюсь.

Прочие сведения: npm версии 6.14.8 реагировать на версию 17.0.1

Есть идеи, откуда эта ошибка или какие шаги я могу сделать, чтобы ее отследить?

3 ответа

Лучший ответ

TL; DR Требуется для обновления версии узла

Я попытался npx create-react-app подтвердить, была ли проблема в шаблоне или в коде проекта. При этом я получил сообщение о том, что для зависимостей моего пакета требуется более высокая версия узла (я был на версии 10.4, последняя версия — 15.2.0).

Выполнение brew upgrade установило последнюю версию, но не изменило версию узла по умолчанию в системе (т. Е. node -v по-прежнему показывал v10.4), но
выполнение nvm install --lts, затем nvm alias-default [latest-version] устранило мою проблему!


2

Danielle C
14 Ноя 2020 в 15:14

Для меня понижение версии react-scripts до последней версии 3.x решило мою проблему. Мне не удалось обновить версию NodeJS, так как у меня не было доступа к экземпляру сервера NodeJS. Кажется, он лучше подходит для React 16.x.

Я запускаю и создаю приложение на NodeJS V10.0.0.


0

Luiz Fernando da Silva
13 Янв 2021 в 17:55

Это может быть связано с eslint в приложении create-react-app

Попробуйте переустановить eslint или eslint-config-response-app
https://github.com/AtomLinter/linter-eslint/issues/1351

BaseConfig — это переменная модуля react-scripts create-response-app в node_modules / response-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')],


0

Ryu
14 Ноя 2020 в 15:09

Recommend Projects

  • React photo

    React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo

    Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo

    Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo

    TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo

    Django

    The Web framework for perfectionists with deadlines.

  • Laravel photo

    Laravel

    A PHP framework for web artisans

  • D3 photo

    D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Visualization

    Some thing interesting about visualization, use data art

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo

    Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo

    Microsoft

    Open source projects and samples from Microsoft.

  • Google photo

    Google

    Google ❤️ Open Source for everyone.

  • Alibaba photo

    Alibaba

    Alibaba Open Source for everyone

  • D3 photo

    D3

    Data-Driven Documents codes.

  • Tencent photo

    Tencent

    China tencent open source team.

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Initial d arcade stage 8 shader error
  • Ini file not configured как исправить half life 2
  • Info install error skip csv file creation
  • Info error name has already been taken
  • Info defaillant ошибка ситроен c4

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии