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.

Require is not defined on electron

See original GitHub issue

Current behavior:

require is not defined inside index.html

image

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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jennifer-shehanecommented, Jul 10, 2019

@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.

0reactions
gtamascommented, Jul 10, 2019

ok thx

Read more comments on GitHub >

github_iconTop 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 >

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