与电子结合使用console.log() [英] using console.log() with electron

查看:55
本文介绍了与电子结合使用console.log()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了很多人在尝试从渲染过程中控制台日志的问题,这不是我的问题,我的console.log堆满了我的主要代码,而我的控制台中看不到任何东西,这是我的代码。

I have seen a lot of questions from people trying to console log from the rendering process, this is NOT my problem I have console.log littering my main code and I don't see anything in my console here is my code.

/* 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以及与该项目关联的所有模块,并尝试创建一个新控制台并记录到该控制台,但是它似乎没有显示出来,我是否缺少任何内容?我已经花了几个小时准备放弃。

I don't see a single log other than the ones produced by electron itself I've tried throwing errors and those work fine but anything console.* related doesn't work at all, I've tried running it in PowerShell and re-pulling from GitHub, my friend can see the console logs when he pulls the project though so it seems I'm isolated. I've also updated NPM and all modules associated with the project AND I've tried creating a new console and logging to that one but it doesn't seem to show up, am I missing something? I've put hours into this and am ready to give up.

推荐答案

我感到您很痛苦。我的一个盒子(Server2012盒子)上有这个问题。在我偶然发现关于其中一个电子的此评论之前,对我没有任何帮助发出线程。

I feel your pain. I have this issue on one of my boxes (a Server2012 box). Nothing worked for me until I stumbled across this comment on one of the electron issues threads.

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

Typically when you install electron you will have a script in your package.json that looks like this.

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

我将我的名字更改为

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

然后我开始从Powershell的主电子过程中获取日志。

And I started to get logging from the main electron process in powershell.

请注意,如果您使用的是较新的版本电子,您可能需要将电子预制的更改为电子

Note that if you are using newer versions of electron, you may need to change electron-prebuilt to electron.

这篇关于与电子结合使用console.log()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆