問題描述
我已經看到很多人試圖從渲染過程中控制日志,這不是我的問題我有 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() 與電子一起使用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!