Uncaught ReferenceError: __webpack_require__ is not defined
See original GitHub issueMy 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:
- Created 6 years ago
- Comments:19 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Was this ever fixed? Still getting this error and removing the obfuscator fixes it, however I need the obfuscator for prod 😄
Still getting this error on v2.6.0