Electron app Uncaught ReferenceError:未定义导出

时间:2017-07-19 13:47:04

标签: javascript electron

我正在尝试在我的电子应用程序中实现身份验证过程,但在加载页面后,我收到了一些异常: console log

我的代码

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
}) 

2 个答案:

答案 0 :(得分:1)

'node-integration': false禁用nodejs功能,例如模块导入和导出require,以及访问node {s}模块,如fspath等,以及通过npm安装的任何模块/纱。这就是您无法加载模块的原因。

答案 1 :(得分: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 install)