Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Uncaught ReferenceError: require is not defined #925

Open
zacard-orc opened this issue Sep 19, 2019 · 6 comments
Open

Uncaught ReferenceError: require is not defined #925

zacard-orc opened this issue Sep 19, 2019 · 6 comments

Comments

@zacard-orc
Copy link

Describe the issue / bug.

# Hi,When I upgrade to electron 5+,and run "yarn run unit",I got a error from the result .
So I try some method ,just like replace webpack target , delete nodejs lib in render directory, add the global windows.require, but all the methods has no working.

19 09 2019 09:41:24.192:INFO [Electron 6.0.9 (Node 12.4.0)]: Connected on socket VGoQJwhg7brt0Hs-AAAA with id 23424134
Electron 6.0.9 (Node 12.4.0) ERROR
Uncaught ReferenceError: require is not defined
at webpack:///external%20%22fs%22:1:1 <- index.js:2:130124

Electron 6.0.9 (Node 12.4.0): Executed 0 of 0 ERROR (1.413 secs / 0 secs)

Dose any body can run this project by electron 5+ ?

How can I reproduce this problem?

# upgrade to electron 5+,and run "yarn run unit"

If visual, provide a screenshot.

#
image

Tell me about your development environment.
  • Node version: 10.16.1
  • NPM version: 6.9.0
  • vue-cli version: (if necessary)
  • Operating System: Win10

If you are looking to suggest an enhancement or feature, then feel free to remove everything above.

@zhouyangit
Copy link

As of version 5, the default for nodeIntegration changed from true to false. You can enable it when creating the Browser Window

 mainWindow = new BrowserWindow({
        webPreferences: {
            nodeIntegration: true
        }
    })

@zacard-orc
Copy link
Author

As of version 5, the default for nodeIntegration changed from true to false. You can enable it when creating the Browser Window

 mainWindow = new BrowserWindow({
        webPreferences: {
            nodeIntegration: true
        }
    })

https://electronjs.org/docs/faq
I had try this method , but no effecting :(

I try many demo ,but their electron version is too old , I have to use the latest version and config group.

Now ,this repo is the best and every feature is passed except for unit test

Electron 6.0.10 (Node 12.4.0) ERROR
{
"message": "Uncaught ReferenceError: require is not defined\nat webpack:///external%20%22path%22:1 <- index.js:7:116304\n\nundefined",
"str": "Uncaught ReferenceError: require is not defined\nat webpack:///external%20%22path%22:1 <- index.js:7:116304\n\nundefined"
}

@f2rge
Copy link

f2rge commented Sep 24, 2019

check the answer here #855

@ChrGriffin
Copy link

ChrGriffin commented Nov 15, 2019

I am also encountering this problem. I have tried many solutions found both here and elsewhere and none seem to be working. My dependencies all seem to be up to date (Electron is at 7+), and nodeIntegration is true for my browser, but when I try to run unit tests, I get the same error:

Electron 7.1.1 (Node 12.8.1) ERROR
  {
    "message": "Uncaught ReferenceError: require is not defined\nat webpack:///external%20%22path%22:1 <- index.js:7:119938\n\nundefined",
    "str": "Uncaught ReferenceError: require is not defined\nat webpack:///external%20%22path%22:1 <- index.js:7:119938\n\nundefined"
  }

My project has just reached the point where TDD is a necessity, so this has the potential to completely halt my development until I can find a fix.

EDIT: Mac OS Mojave 10.14.5, Node 12.8.1, NPM 6.13.0

@MarcinSulowski
Copy link

Same here.
Electron 6.0.12 (Node 12.4.0) ERROR { "message": "Uncaught ReferenceError: require is not defined\nat webpack:///external%20%22path%22:1 <- index.js:13:8104\n\nundefined", "str": "Uncaught ReferenceError: require is not defined\nat webpack:///external%20%22path%22:1 <- index.js:13:8104\n\nundefined" }

Also tried updating karma-electron to the newest version 6.3.0 which is supposed to solve the require issues related to nodeIntegration, but no luck.

Windows 10, Electron 6.0.12, Node 12.4.0, npm 6.4.1

@NoelDavies
Copy link

Had anybody solved this? o.0 I get the same

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants