Require is not defined on electron
See original GitHub issueCurrent behavior:
require is not defined
inside index.html
Desired behavior:
Renders successfully
Steps to reproduce:
My index.html contains this inside <script>
tag. Webpack preprocessing didn’t make sense.
window.addEventListener("keydown", e => {
if (e.ctrlKey && e.shiftKey && e.key === "I") { // для возможности открытия в релизных версиях
let remote = require("electron").remote;
remote.getCurrentWindow().toggleDevTools();
}
});
// You can also require other files to run in this process
let render = require('./out/App').render;
render('id1');
Versions
macOS High Sierra 10.13.3
Cypress 2.1.0
Electron 1.8.2
Webpack preprocessing plugin 1.1.3
Webpack 3.6.0
I am also using typescript and es6.
Webpack preprocessor config
const wp = require('@cypress/webpack-preprocessor')
module.exports = (on) => {
const options = {
webpackOptions: {
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: [/node_modules/],
use: [{
loader: 'ts-loader',
}],
},
],
},
},
}
on('file:preprocessor', wp(options))
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Electron require() is not defined - Stack Overflow
The solution is to not give the renderer direct access to node (ie. require() ), but to give our electron main process access...
Read more >Electron 12.0.0 'Require' is not defined · Issue #463 - GitHub
Hey! I am running into a problem using this quick start. Before I package the app, everything works fine and the node 'require'...
Read more >How to solve require is not defined in electronjs - YouTube
How to solve require is not defined in electron js ?Solution:I have solved this issue by updating ElectronJs VersionLet Update it to the ......
Read more >electron 5.0.0 "Uncaught ReferenceError: require is not defined"
JavaScript : electron 5.0.0 "Uncaught ReferenceError: require is not defined " [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] ...
Read more >ReferenceError: require is not defined in JavaScript | bobbyhadz
To solve the "ReferenceError require is not defined" error, use the ES6 module import and export syntax. The require() function is Node.js specific...
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
@gtamas We haven’t done any development on the feature to support Electron testing yet, so I wouldn’t say it will come relatively soon.
ok thx