Monday, 21 March 2022

Requiring external module @babel/register ReferenceError: require is not defined

I have a front-end build, which I was given and which I am trying to get to build. Whenever I run yarn run dev, I get the following:

(base) ➜  project git:(master) ✗ yarn run dev
yarn run v1.22.17
$ gulp
[22:18:45] Requiring external module @babel/register
ReferenceError: require is not defined
    at file:///home/user/sites/project/gulpfile.babel.js:5:20
    at ModuleJob.run (internal/modules/esm/module_job.js:145:37)
    at async Loader.import (internal/modules/esm/loader.js:182:24)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

What can I do to troubleshoot and fix this?

My installation steps were as follows:

yarn global add gulp-cli
yarn global add bem-tools-core
yarn
yarn run dev

I have tried installing with npm as well, just in case it might make a difference. It does not. The same error persists.

The top of the gulpfile.babel.js looks as follows:

"use strict";

import gulp from "gulp";

const requireDir = require("require-dir"),
    paths = {
        views: {
            src: [
                "./src/views/index.pug",
                "./src/views/pages/*.pug"
            ],

The package.json is like this:

{
    "name": "gulp-pug-starter",
    "description": "Frontend development with pleasure",
    "author": "Andrey Gorokhov",
    "repository": {
        "type": "git",
        "url": "https://github.com/andreyalexeich/gulp-pug-starter.git"
    },
    "license": "MIT",
    "type": "module",
    "babel": {
    "presets": [
        "es2015"
    ]
    },
    "scripts": {
        "dev": "gulp",
        "build": "gulp prod --production",
        "build:views": "gulp views --production",
        "build:styles": "gulp styles --production",
        "build:scripts": "gulp scripts --production",
        "build:images": "gulp images --production",
        "build:webp": "gulp webp --production",
        "build:sprites": "gulp sprites --production",
        "build:fonts": "gulp fonts --production",
        "build:favicons": "gulp favicons --production",
        "build:gzip": "gulp gzip --production",
        "lint:styles": "stylelint \"src/**/*.scss\" --syntax=scss",
        "lint:styles --fix": "stylelint \"src/**/*.scss\" --syntax=scss --fix",
        "lint:scripts": "eslint --color ./src/blocks",
        "lint:scripts --fix": "eslint --fix --color ./src/blocks",
        "bem-c": "bem create $* -l src/blocks/components",
        "bem-m": "bem create $* -l src/blocks/modules"
    },
    "devDependencies": {
        "@babel/core": "^7.4.3",
        "@babel/preset-env": "^7.4.3",
        "@babel/register": "^7.17.0",
        "babel-eslint": "~10.1.0",
        "babel-loader": "^8.0.5",
        "babel-register": "^6.26.0",
        "bem-tools-core": "bem-tools/bem-tools-core",
        "bem-tools-create": "bem-tools/bem-tools-create",
        "browser-sync": "^2.23.6",
        "del": "^5.1.0",
        "eslint": "~7.7.0",
        "gulp": "^4.0.0",
        "gulp-autoprefixer": "~7.0.1",
        "gulp-clean-css": "~4.3.0",
        "gulp-debug": "~4.0.0",
        "gulp-favicons": "^2.3.1",
        "gulp-group-css-media-queries": "^1.2.2",
        "gulp-if": "^3.0.0",
        "gulp-imagemin": "~7.1.0",
        "gulp-newer": "^1.4.0",
        "gulp-plumber": "^1.2.0",
        "gulp-pug": "^4.0.1",
        "gulp-rename": "^2.0.0",
        "gulp-replace": "^1.0.0",
        "gulp-sass": "~4.1.0",
        "gulp-sourcemaps": "^2.6.4",
        "gulp-svg-sprite": "^1.5.0",
        "gulp-watch": "^5.0.0",
        "gulp-webp": "^4.0.1",
        "husky": "^4.2.1",
        "imagemin-giflossy": "^5.1.10",
        "imagemin-jpeg-recompress": "~7.0.0",
        "imagemin-mozjpeg": "^9.0.0",
        "imagemin-pngquant": "~9.0.0",
        "imagemin-webp": "^6.0.0",
        "imagemin-zopfli": "^7.0.0",
        "lint-staged": "^10.0.3",
        "require-dir": "^1.2.0",
        "stylelint": "^13.6.1",
        "stylelint-order": "^4.1.0",
        "stylelint-selector-bem-pattern": "^2.1.0",
        "webpack": "~4.44.1",
        "webpack-stream": "^5.2.1",
        "yargs": "~15.4.1"
    },
    "dependencies": {
        "bootstrap": "^5.1.1",
        "gsap": "./gsap-bonus.tgz",
        "headroom.js-latest": "^0.9.6",
        "jquery": "^3.6.0",
        "jquery-ui_1.12": "^1.12.0",
        "magnific-popup": "^1.1.0",
        "owl.carousel": "^2.3.4",
        "popper.js": "^1.16.1",
        "smart-grid": "^2.1.2",
        "swiper": "6.8.4"
    },
    "husky": {
        "hooks": {
            "pre-commit": "lint-staged"
        }
    },
    "lint-staged": {
        "!(_*).scss": [
            "stylelint --fix --color --config ./.stylelintrc"
        ],
        "*.js": [
            "eslint --fix --color"
        ]
    }
}


from Requiring external module @babel/register ReferenceError: require is not defined

No comments:

Post a Comment