将 console.log() 与电子一起使用

2023-01-29前端开发问题
7

本文介绍了将 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.

通常,当您安装 electron 时,您的 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.

请注意,如果您使用较新版本的电子,您可能需要将 electron-prebuilt 更改为 electron.

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

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

The End

相关推荐

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui tree树组件怎么自定义添加图标
经常用到layui的朋友都知道,layui tree默认是不能自定义图标的,那么我们要自定义的话要怎么操作呢? 首先用编辑器软件(修改时候用编辑器记得编码),打开layui.js。搜索: i class="layui-icon layui-icon-file" 改为如下代码: i class="'+ (i.icon || "l...
2024-10-26 前端开发问题
493

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125

JavaScript(js)文件字符串中丢失"\"斜线的解决方法
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转...
2024-10-17 前端开发问题
437

layui弹出层layer.open中的content问题
如果content取的的事当前页面元素内容时,type类型应该为1 layer.open({type: 1,title: '内容区域',content: $('#DIV_EditUserInfo'), // 设置跳转的div,跳转到对应的页面area: ["920px", "250px"],}); 如果content取的的路径,或者某个页面,type类型应该为...
2024-10-15 前端开发问题
460