Uncaught Error: Cannot find module ‘jquery’

tl;dr In contrast to a normal nodejs app, where you have access to global modules (e.g. located in /usr/bin/node), electron doesn’t automatically set the NODE_PATH environment variables. You have to set it manually to all the paths containing your desired modules. Update: The answer to the question why require(“ipc”) is working and require(“jquery”) not? is … Read more

Typescript + React/Redux: Property “XXX” does not exist on type ‘IntrinsicAttributes & IntrinsicClassAttributes

So after reading through some related answers (specifically this one and this one and looking at @basarat’s answer to the question, I managed to find something that works for me. It looks (to my relatively new React eyes) like Connect was not supplying an explicit interface to the container component, so it was confused by … Read more

Electron nodeIntegration not working, also general weird Electron behavior [duplicate]

Electron 12 is now defaulting contextIsolation to true, which disables Node (here are the release notes; and here’s the PR). Here’s a discussion of this change. nodeIntegration for what it’s worth is going to be removed in a future Electron version. The easiest way to fix this is to simply disable context isolation: mainWindow = … Read more

How to close electron app via javascript?

you can use const remote = require(‘electron’).remote let w = remote.getCurrentWindow() w.close() to close your app. if you are using jQuery const remote = require(‘electron’).remote $(‘#close-btn’).on(‘click’, e => { remote.getCurrentWindow().close() }) if you are using Vue.js <template> <button @click=”close”><i class=”fa fa-cube” aria-hidden=”true”></i>&nbsp; Close application</button> </template> <script> const remote = require(‘electron’).remote export default{ data(){ return { … Read more

Saving files locally with electron

If you are targeting multiple platforms, I answered a similar question here. Basically app.getPath(name), app.setPath(name, path), and app.getAppPath() are very useful in saving files to the the right place regardless of the OS. You may also want to check out these Nodejs packages which help simplify saving files directly to the host machine… fs-jetpack graceful-fs … Read more

How do I reload a page with react-router?

firstly, add react-router as a dependency yarn add react-router or npm install react-router Then (for react-router v5) import { useHistory } from ‘react-router’ const history = useHistory() // then add this to the function that is called for re-rendering history.go(0) This causes your page to re-render automatically For react-router v6 use the useNavigate hook instead: … Read more

What is the difference between const and const {} in JavaScript

The two pieces of code are equivalent but the first one is using the ES6 destructuring assignment to be shorter. Here is a quick example of how it works: const obj = { name: “Fred”, age: 42, id: 1 } //simple destructuring const { name } = obj; console.log(“name”, name); //assigning multiple variables at one … Read more