[英]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:我正在尝试在 Electron 项目中使用 nodemon 包,但是当我尝试使用
nodemon main.js
执行此包时,我在终端中发现了此错误:
But when I try to execute simply with "npm electron ."但是当我尝试简单地使用“npm electron”执行时。 this works properly.
这工作正常。 Why?
为什么?
The code of main.js
: 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);
I've resolved it.我已经解决了。
In package.json I changed the "start": "nodemon ./main.js"
to " watch": "nodemon --exec electron ."
在 package.json 中,我将
"start": "nodemon ./main.js"
更改为 " watch": "nodemon --exec electron ."
and it worked.它奏效了。
You can resolve it by executing electron with npx:您可以通过使用 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
Step 1: As "Fabrício Pinto Ferreira" Said change package.json第 1 步:如“Fabrício Pinto Ferreira”所说更改 package.json
"start": "nodemon ./main.js" to
"watch": "nodemon --exec electron ."
and it was showing error of electron它显示电子错误
Step 2: I installed node globally第 2 步:我全局安装了节点
npm i -g electron
That worked for me.那对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.