用电子console.log()

我看到很多人试图从渲染过程控制日志,这不是我的问题我有console.log乱丢我的主代码,我没有看到我的控制台中的任何东西这里是我的代码。

/* eslint-disable no-undef */ const { app, BrowserWindow, ipcMain } = require('electron'); const path = require('path'); const url = require('url'); /* eslint-enable */ let win; console.log('console log test'); function createWindow() { win = new BrowserWindow({ width: 800, height: 800 }); win.loadURL(url.format({ pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true })); win.on('close', () => { win = null; }); console.log('console log test'); } app.on('ready', createWindow); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', () => { if (win == null) { console.log('console log test'); createWindow(); console.log('console log test'); } }); 

我没有看到一个单一的日志,而不是由电子本身产生的日志我已经尝试抛出错误,那些工作正常,但任何控制台。*相关并不工作,我试着在PowerShell中运行它,从GitHub拉,我的朋友可以看到控制台日志,当他拉动项目,所以看起来我是孤立的。 我也更新了NPM和与该项目相关的所有模块,我试图创build一个新的控制台并logging到该项目,但似乎并没有显示出来,我错过了什么? 我已经放了几个小时,准备放弃。

我感到你的痛苦。 我在我的一个盒子(Server2012盒子)上有这个问题。 在我偶然发现电子问题主题之一的这个评论之前,没有任何工作可以帮助我。

通常当您安装电子时,您的package.json中将会有一个脚本,如下所示。

 "scripts": { "start": "electron .", } 

我改变了我的

 "scripts": { "start": "C:/path/to/project/node_modules/electron-prebuilt/dist/electron.exe .", } 

我开始从powershell的主要电subprocess中获取日志。

请注意,如果您使用较新版本的电子,则可能需要将electron-prebuiltelectron