question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught ReferenceError: __webpack_require__ is not defined

See original GitHub issue

erro

My config file:

const webpack = require('webpack');
const JavaScriptObfuscator = require('webpack-obfuscator');
const path = require('path');

const BUILD_DIR = path.resolve(__dirname, './public');
const APP_DIR = path.resolve(__dirname, 'src/');

const config = {
  entry: `${APP_DIR}/index.js`,

  output: {
    path: BUILD_DIR,
    filename: 'bundle.js',
  },
  devServer: {
    historyApiFallback: true,
  },
  module: {
    loaders: [
      {
        enforce: 'pre',
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'eslint-loader',
      },
      {
        test: /\.js$/,
        include: APP_DIR,
        loader: 'babel-loader',
      },
      {
        test: /\.(png|jpg|gif)$/,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: 'images/[name].[ext]',
            },
          },
        ],
      },
      {
        test: /\.(gif|png|jpe?g|svg)$/i,
        use: [
          'file-loader',
          {
            loader: 'image-webpack-loader',
          },
        ],
      },
    ],
  },
  plugins: [
    new JavaScriptObfuscator({
      rotateUnicodeArray: false,
    }),
  ],
};

module.exports = config;

My package.json:

  "name": "whatever",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "babel-preset-stage-2": "^6.24.1",
    "backendless": "^4.3.0",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^14.1.0",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^4.0.0",
    "eslint-plugin-react": "^6.10.3",
    "react": "^16.0.0",
    "react-bootstrap": "^0.31.5",
    "react-dom": "^16.0.0",
    "react-redux": "^5.0.6",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.0.14",
    "redux": "^3.7.2",
    "redux-persist": "^5.4.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "watch": "webpack -d --watch",
    "build": "webpack",
    "serve": "serve ./public"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "file-loader": "^1.1.6",
    "image-webpack-loader": "^3.4.2",
    "serve": "^6.4.3",
    "webpack": "^3.10.0",
    "webpack-obfuscator": "^0.13.0"
  }
}

I’m not sure why this is happening, any help is appreciated.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
aliicommented, Oct 2, 2019

Was this ever fixed? Still getting this error and removing the obfuscator fixes it, however I need the obfuscator for prod 😄

1reaction
m4heshdcommented, Jan 20, 2021

Still getting this error on v2.6.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack : Uncaught ReferenceError: require is not defined
in web app. According to https://github.com/liady/webpack-node-externals it is only for backend. Since you use nodeExternals in web app ...
Read more >
Uncaught ReferenceError: require is not defined #17 - GitHub
When I add this to my commonconfig in webpack, it throws this error. I can't understand why is it occurring or how to...
Read more >
How To Fix ReferenceError require is not defined in JavaScript
In this case, check your package.json file for an property called type . If that is set to module , ES6 modules will...
Read more >
Fix "require is not defined" in JavaScript/Node - Stack Abuse
You're trying to use require in a file ending in .mjs , which typically specifies ES modules. Node. If you encounter this error...
Read more >
How to fix the error `require is not defined` in Node.js
Today I started writing a new project on Node.js and got this error on the very first run: const express = require('express'); ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found