2017-07-19 70 views
-1

我想實現身份驗證過程在我的電子應用程序,但加載頁面後,我收到例外量: console log電子應用未捕獲的ReferenceError:出口沒有定義

我的代碼

mainWindow = new BrowserWindow({ width: 800, height: 600, 
show: false, 'node-integration': false }) 
mainWindow.loadURL(authUrl); 
mainWindow.show(); 

function handleCallback(url) { 

} 

mainWindow.webContents.on('will-navigate', function(event, url) { 
    handleCallback(url); 
}) 

mainWindow.webContents.on('did-get-redirect-request', function(event, oldUrl, newUrl) { 
    handleCallback(newUrl); 
}) 

// Emitted when the window is closed. 
mainWindow.on('closed', function() { 
    mainWindow = null 
}) 
+0

有沒有在你的代碼中沒有出口。 –

+0

我知道,但我還沒有找到一種方法來定義他們在我的應用程序(抱歉,我不是一個JS程序員它只是一個支持項目) –

回答

0

我通過包括幾個模塊解決的問題:

const electron = require('electron') 
const app = electron.app 
const BrowserWindow = electron.BrowserWindow 
const 
const redirectUri = 'your redirect'; 
let mainWindow 

const qs = require('querystring'), 
     shell = require('shell'), 
     _ = require('lodash'), 
     path = require('path'), 
     url = require('url') 

function createWindow() { 

var querystring = require('querystring'); 
var https = require('https'); 
var clientId = 'your client id'; 
var scope = ['account-info', 'operation-history', 'operation-details']; 
var authUrl = 'https://money.yandex.ru/oauth/authorize?'; 
var apiUrl = 'https://money.yandex.ru/api'; 
var authUrl = authUrl + 'client_id=' + clientId + 
    '&redirect_uri=' + redirect_uri + 
    '&scope=' + scope.join(" ") + 
    '&response_type=' + 'code'; 

let token = null; 

authWindow = new BrowserWindow({ 
    width: 600, 
    height: 400, 
    type: 'splash', 
    webPreferences: { 
     nodeIntegration: false 
    } 
}); 

authWindow.on('closed', function() { 
    authWindow = null; 
    resolve(token); 
}); 

authWindow.webContents.on('new-window', function(e, url) { 
    e.preventDefault(); 
    shell.openExternal(url); 
}); 
authWindow.webContents.on('will-navigate', function (event, url) { 
    console.log(url); 
}); 

authWindow.webContents.on('did-get-redirect-request', function (event, 
oldUrl, newUrl) { 
console.log(newUrl); 
}); 

authWindow.loadURL(authUrl); 
} 


app.on('ready', createWindow) 

app.on('window-all-closed', function() { 
    if (process.platform !== 'darwin') { 
     app.quit() 
    } 
}) 

app.on('activate', function() { 
    if (mainWindow === null) { 
     createWindow() 
    } 
}) 

不要忘記NPM安裝)

0

'node-integration': false通過require禁用nodejs功能,如模塊導入和導出,以及訪問nodejs模塊,如fspath等,以及通過npm/yarn安裝的任何模塊。這就是爲什麼你無法加載你的模塊。

相關問題