Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

578
Visualizações
Error: ERR_FAILED (-2) loading electronjs when closing and opening new window

I'm trying to open a app loader like window that will open first upon running the app just to cover some async scripts running and upon completion, the loader window will close and open the main window, below is my attempt

let mainWindow;
let win;
let loaderwin;

// CREATE WINDOW
const createMainWindow = async () => {
    win = new BrowserWindow({
        title: app.name,
        show: false,
        width: 1024,
        height: 768,
    });

    if( isdebug ) win.webContents.openDevTools();

    win.on('ready-to-show', () => {     
        win.maximize();
        win.show();
    });

    win.on('closed', () => {
        mainWindow = undefined;
    });

    await win.loadFile(path.join(__dirname, 'main-window.html'));

    return win;
}

const createLoaderWindow = async () => {
    loaderwin = new BrowserWindow({
        title: app.name,
        show: false,
        width: 600,
        height: 300,
        frame : false,
        webPreferences : {
            devTools : false
        }
    });

    loaderwin.on('ready-to-show', () => {
        loaderwin.show();
    });

    loaderwin.on('closed', () => {
        // on close open the mainwindow
        mainWindow = createMainWindow();
    });

    await loaderwin.loadFile(path.join(__dirname, 'loader.html'));

    return loaderwin;
}

// Prevent multiple instances of the app
if (!app.requestSingleInstanceLock()) {
    app.quit();
}

app.on('second-instance', () => {
    if (mainWindow) {
        if (mainWindow.isMinimized()) {
            mainWindow.restore();
        }

        mainWindow.show();
    }
});

app.on('window-all-closed', () => {
    if (!is.macos) {
        app.quit();
    }
});

app.on('activate', async () => {
    if (!mainWindow) {
        mainWindow = await createLoaderWindow();
    }
});


(async () => {
    
    await app.whenReady();

    Menu.setApplicationMenu(null);
    mainWindow = createLoaderWindow();

    await syncfunct();

    ( require('./server.js'))();

    // done, close loader window
    loaderwin.close();

})();

but it gives me this error

Error: ERR_FAILED (-2) loading 'file:///D:\web-development\github\tordyak-app\loader.html' at rejectAndCleanup (electron/js2c/browser_init.js:217:1457) at Object.stopLoadingListener (electron/js2c/browser_init.js:217:1832) at Object.emit (events.js:315:20) { errno: -2, code: 'ERR_FAILED', url: 'file:///D:\web-development\github\tordyak-app\loader.html' }

any help, ideas, suggestions is greatly appreciated. Thank you in advance.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

See https://github.com/electron/electron/issues/18857

  • Check that the URL is right: open it in Firefox (not in Chrome which won't allow file url as a default)
  • Check that your preload JavaScript script is ok
  • Check that your window config is ok

This error might be related to various issue like having a wrong path, or having a bug during the window initialization.

about 4 years ago · Juan Pablo Isaza Relatório

0

I had the same issue and don't have a real answer why it happens.

But a workaround...

If I open a hidden window during the process of closing and reopening, electron does not break.

async () => {
    app.off('window-all-closed', quitApp);
    const hiddenWin = new BrowserWindow({
        useContentSize: true,
        show: false,
    });
    win.close();
    win = generateWindow();
    hiddenWin.close();
    app.once('window-all-closed', quitApp);
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda