'Using nodemon doesn't recognize Electron package
I'm trying to use the nodemon package in an Electron project but when I try to execute this with nodemon main.js
I catch this error in terminal:
But when I try to execute simply with "npm electron ." this works properly. Why?
The code of main.js
:
const { app, BrowserWindow } = require('electron');
let mainWindow;
createMainWindow = () => {
mainWindow = new BrowserWindow({
width: 1600, height: 900,
webPreferences: {
nodeIntegration: false
}
});
mainWindow.loadFile('./renderer/index.html')
//mainWindow.webContents.openDevTools();
}
app.whenReady().then(createMainWindow);
Solution 1:[1]
I've resolved it.
In package.json I changed the "start": "nodemon ./main.js"
to "watch": "nodemon --exec electron ."
and it worked.
Solution 2:[2]
You can resolve it by executing electron with npx:
"dev": "nodemon --exec npx electron ."
but this will run a new instance every time you make a change.
Alternatively, you can install electron globally:
npm i -g electron
Solution 3:[3]
Step 1: As "FabrÃcio Pinto Ferreira" Said change package.json
"start": "nodemon ./main.js" to
"watch": "nodemon --exec electron ."
and it was showing error of electron
Step 2: I installed node globally
npm i -g electron
That worked for me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | FabrÃcio Pinto Ferreira |
Solution 2 | |
Solution 3 | MARK I |