Repository navigation
Closed
Labels
help wantedMaintainers welcome a community PR for thisstatus: staleNo author response after a needs: request; close candidate
Description
Bug report
I have an Electron based application. we do webpack in the render process. It throws error when I run the app
Uncaught ReferenceError: global is not defined
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
It should not throw this error when I run the application
Other relevant information:
here is the Error:
index.js?e792:25 Uncaught ReferenceError: global is not defined
at eval (index.js?e792:25)
at Object../node_modules/@babel/polyfill/lib/index.js (feb33beb921cb1f5a1b3.worker.js:97)
at __webpack_require__ (feb33beb921cb1f5a1b3.worker.js:20)
at eval (eval at ./node_modules/babel-loader/lib/index.js?{"babelrc":false,"presets":["@babel/preset-env", "@babel/preset-react"]}!./node_modules/ts-loader/index.js?{"transpileOnly":true,"configFile":"tsconfig.webpack.json"}!./node_modules/ts-loader/index.js?!./packages/myApp/modules/frameworks/file-provider/box-provider/webworker/box.worker.ts (feb33beb921cb1f5a1b3.worker.js:526), <anonymous>:2:73)
at Module../node_modules/babel-loader/lib/index.js?{"babelrc":false,"presets":["@babel/preset-env", "@babel/preset-react"]}!./node_modules/ts-loader/index.js?{"transpileOnly":true,"configFile":"tsconfig.webpack.json"}!./node_modules/ts-loader/index.js?!./packages/myApp/modules/frameworks/file-provider/box-provider/webworker/box.worker.ts (feb33beb921cb1f5a1b3.worker.js:526)
at __webpack_require__ (feb33beb921cb1f5a1b3.worker.js:20)
at feb33beb921cb1f5a1b3.worker.js:84
at feb33beb921cb1f5a1b3.worker.js:87
Note: Since it is an electron app:
config.target = "electron-renderer";
{global:true};
webpack version: ^4.41.2
Node.js version: 10.16.3
Operating System: windows 10
"@babel/core": "^7.6.4"
Additional tools: chrome 78
Electron version : 7.1.1
Reacted by Searene, J M Rossy, Jakub Žák, Lucas Sanz Gorostiaga, Praveer Kumar, Austin Adams, Travers Biddle, iamart and Philip Lin
Metadata
Metadata
Assignees
Labels
help wantedMaintainers welcome a community PR for thisstatus: staleNo author response after a needs: request; close candidate
Type
Fields
Priority
None yet
Activity
sokra commentedon Nov 26, 2019
Thanks for your report. It would be great if you reduce your issue to a small reproducible example. Best put this example into a github repository together with instructions how to get to the problem.
Praveer1981 commentedon Nov 26, 2019
Its little bit hard to reproduce it in the separate application. I want to know under which scenario it is possible.
once I get the error in the console and write
globalIt shows me the property of the global object which means the global object is available.then what could be the reason of getting this error ?
alexander-akait commentedon Nov 26, 2019
@Praveer1981 Looks like you run
babel-loaderin worker, why?Praveer1981 commentedon Nov 26, 2019
we have
babel-loaderin the webpack config filePraveer1981 commentedon Nov 26, 2019
`module.exports = {
....
module: {
rules: [
{
test: /.ts(x?)$/,
include: [packagesDir],
use: [
{
loader: require.resolve("babel-loader"),
options: {
babelrc: false,
presets: [
[
"@babel/preset-env",
{
modules: false,
"useBuiltIns" : "entry"
}
],
"@babel/preset-react"
],
plugins: [require.resolve("babel-plugin-syntax-dynamic-import")]
}
},
{
loader: require.resolve("ts-loader"),
options: {
configFile: "tsconfig.webpack.json"
}
}
]
}
}
.....
}`
Praveer1981 commentedon Nov 26, 2019
Additional Information:
if (global._babelPolyfill && typeof console !== "undefined" && console.warn) {
console.warn("@babel/polyfill is loaded more than once on this page. This is probably not desirable/intended " + "and may have consequences if different versions of the polyfills are applied sequentially. " + "If you do need to load the polyfill more than once, use @babel/polyfill/noConflict " + "instead to bypass the warning.");
}
ohanar commentedon Feb 18, 2020
Here is an minimal example repository that runs into this issue: https://github.com/ohanar/webpack-issue-10035/
amanharwara commentedon Mar 13, 2020
I was having the same issue, and I found a hacky fix.
If you can, change any reference of
globalwhich is causing the issue towindow.globalThis. At least this worked for me.EdwinIwan commentedon Mar 24, 2020
We found easy solution for this bug. We had to only add this code to index.html before your bundle.
fix global in `electron-renderer` target
webpack-bot commentedon Sep 22, 2020
This issue had no activity for at least three months.
It's subject to automatic issue closing if there is no activity in the next 15 days.
alexander-akait commentedon Sep 22, 2020
Fixed in
worker-loader, also webpack@5 supports workers out of box21 remaining items
YasharSL commentedon Oct 15, 2022
I'm having the same issue while trying to open a new window in my app. None of the solutions worked.
marcibk commentedon Oct 19, 2022
Did anyone found a fix on how to use
nodeIntegration: false?bpejac commentedon Nov 13, 2022
@marcibk I set
target: 'web'in the webpack config for the react app. I do not setnodeIntegration(defaults to false AFAIK).CarlSaqui29 commentedon Dec 3, 2022
on your createWindow(), add the
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
this will work absolutely...
Cedgud commentedon Feb 3, 2023
Hello,
does anone make this work? I've tried the global = globalThis fix. Now I have "require is not defined"
thamizh-qwerty commentedon Feb 28, 2023
It does not works in angular + electronJS + contextIsolation = true
resatDev commentedon Sep 21, 2023
I have already resolved this problem by changing the
nodeoptions. According to official doc of webpack,global prop of nodeis false default. Using suggested plugin or makingglobal is truewill probably resolve your problem as well.travbid commentedon May 25, 2024
For my project I had to set
splitChunks: falsein the webpack config to fix this error:sabelyn commentedon Jun 2, 2024
I'll join in here. Tried both combinations of
nodeIntegrationandcontextIsolationand those solutions failed. Tried defining global in my index.html file, which failed. I have tried setups and configurations from at least 5 different "How to setup an electron project with react, webpack, and typescript" articles. I also tried setting node.global to true in all of my various webpack entry configs.The only thing that works is setting
target: "web"in the react webpack config, and this only works when building in development mode running two separate terminal processes for webpack-dev-server and the actual electron app.Something is buggy with the electron-renderer target. Electron apps need global, and electron-renderer isn't providing it. The reference error being thrown isn't even in my own code, so I have no control over whether it's being called or not.
ChuanfengLai commentedon Jun 17, 2024
When create brwoser window, use
nodeIntegrationInWorker: trueinwebPreferenceshttps://www.electronjs.org/docs/latest/tutorial/multithreading
mohan-reviewer1 commentedon Dec 11, 2024
kythanh commentedon Jun 8, 2025
Still got the same error here.
alexander-akait commentedon Jun 10, 2025
@kythanh Check your
target? What is the value?hushuxian commentedon Aug 5, 2025
I have the same problem with my electron app,only set nodeIntegration:true and contextIsolation:false can fix it .
alexander-akait commentedon Aug 5, 2025
@hushuxian Can you create reproducible test repo, thank you