ソースコードとエラーコード
###レンダラープロセス
レンダラープロセスのデベロッパーツールでエラーが表示されました。
エラー内容から、const test = require("remote").require("./index");のあたりで問題が発生しているのではないかと思うのですが解決に至りません。
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta http-equiv="Content-Security-Policy" content="script-src 'unsafe-inline';default-src 'self'; style-src 'self' 'unsafe-inline';" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="css/style.css"> <script type="text/javascript"> const test = require("remote").require("./index"); test.getdw(); </script> <title>Document</title> </head> <body> <section> <h4> <%= name %> </h4> <span id="day"></span> </section> </body> </html>
###メインプロセス
'use strict'; const test = require("./preload"); //Set Usage const electron = require('electron'); const exec = require('child_process').exec; const app = electron.app; const BrowserWindow = electron.BrowserWindow; const Menu = electron.Menu; const dialog = electron.dialog; const ejse = require('ejs-electron'); //const ipcMain = electron.ipcMain; function showAboutDialog() { dialog.showMessageBox({ type: 'info', buttons: ['OK'], message: 'About This App', detail: 'This app was created by @sb-i.jp' }); } function showSettingsWindow(){ var wn = new window_s('Imput'); } function exec_out(cmd){ exec(cmd, (error, stdout, stderr) => { console.log(stdout); }); } class window{ constructor(wname,type) { this.width=1400; this.height=700; let menuTemplate = [{ label: 'アプリケーション', submenu: [ { label: 'About', accelerator: 'CmdOrCtrl+Shift+A', click: function() { showAboutDialog(); } }, { type: 'separator' }, { label: 'Settings', accelerator: 'CmdOrCtrl+,', click: function() { showSettingsWindow(); } }, { type: 'separator' }, { label: 'Quit', accelerator: 'CmdOrCtrl+Q', click: function() { app.quit(); } } ] },{ label: 'サーバ接続', submenu: [ { label: 'About', accelerator: 'CmdOrCtrl+Shift+A', click: function() { showAboutDialog(); } }, { type: 'separator' }, { label: 'Settings', accelerator: 'CmdOrCtrl+S', click: function() { showSettingsWindow(); } }, { type: 'separator' }, { label: 'Quit', accelerator: 'CmdOrCtrl+Q', click: function() { app.quit(); } } ] }]; let menu = Menu.buildFromTemplate(menuTemplate); Menu.setApplicationMenu(menu); this.window=[]; this.window[wname] = new BrowserWindow({ width: this.width, height: this.height, webPreferences: { nodeIntegration: true, contextIsolation: false, // preload: __dirname + '/preload.js', }, 'node-integration': false, }); // this.window[wname] = new BrowserWindow({width:1000,height:700}); this.window[wname].webContents.openDevTools(); this.window[wname].loadURL(`file://${__dirname}/${wname}.${type}`); this.close(wname,function(){}); } /** * @param {String} wname :Window name and Window file name * @param {func} func : Function * */ close(wname, func) { if (func == NaN) { } else { this.window[wname].on('closed', function () { func(); }); } } } class window_s{ constructor(wns,type){ this.width = 1000; this.height = 700; var mw = new window(wns,type); mw.window[wns].webContents.on('did-finish-load', () => { mw.window[wns].webContents.send('getmsg', "Hello!!"); }); } } class window_ejs{ constructor(wname){ this.width = 1000; this.height = 700; this.wname=wname; let menuTemplate = [{ label: 'アプリケーション', submenu: [{ label: 'About', accelerator: 'CmdOrCtrl+Shift+A', click: function () { showAboutDialog(); } }, { type: 'separator' }, { label: 'Settings', accelerator: 'CmdOrCtrl+,', click: function () { showSettingsWindow(); } }, { type: 'separator' }, { label: 'Quit', accelerator: 'CmdOrCtrl+Q', click: function () { app.quit(); } } ] }, { label: 'サーバ接続', submenu: [{ label: 'About', accelerator: 'CmdOrCtrl+Shift+A', click: function () { showAboutDialog(); } }, { type: 'separator' }, { label: 'Settings', accelerator: 'CmdOrCtrl+S', click: function () { showSettingsWindow(); } }, { type: 'separator' }, { label: 'Quit', accelerator: 'CmdOrCtrl+Q', click: function () { app.quit(); } } ] }]; let menu = Menu.buildFromTemplate(menuTemplate); Menu.setApplicationMenu(menu); this.window = []; // this.window[wname] = new BrowserWindow({width:1000,height:700}); //this.window[wname].webContents.openDevTools(); } Drow(type){ ejse.data("name", "test"); this.window[this.wname] = new BrowserWindow({ width: this.width, height: this.height, 'node-integration': false, webPreferences: { nodeIntegration: true, contextIsolation: false, preload: __dirname + '/preload.js', } }); this.window[this.wname].loadURL(`file://${__dirname}/${this.wname}.ejs`); this.close(this.wname, function () { }); this.window[this.wname].webContents.openDevTools(); } /** * @param {String} wname :Window name and Window file name * @param {func} func : Function * */ close(wname, func) { if (func == NaN) { } else { this.window[wname].on('closed', function () { func(); }); } } } exports.getdw = function(){ console.log("test"); } app.on('ready',function(){ test.testws(); var wns = new window_ejs('Menu'); wns.width=500; wns.height=500; wns.Drow("ejs"); });
エラーメッセージ
####レンダラープロセスのデベロッパーツール(コンソール)
Uncaught /Users/***/Desktop/Project/electronwindowbase/node_modules/remote/libs/remote.coffee:8 module.exports = (opts = {}) -> ^ SyntaxError: Unexpected token > at new Script (vm.js:83:7) at createScript (vm.js:265:10) at Object.runInThisContext (vm.js:313:10) at Module._compile (internal/modules/cjs/loader.js:712:26) at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10) at Module.load (internal/modules/cjs/loader.js:645:32) at Function.Module._load (internal/modules/cjs/loader.js:560:12) at Module.require (internal/modules/cjs/loader.js:685:19) at require (internal/modules/cjs/helpers.js:16:16) at file:///Users/***/Desktop/Project/electronwindowbase/Menu.ejs:12:19
情報が少ないですが、どなたか解決用方法を教えていただけらたら幸いです。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/11/21 15:46
2019/11/21 15:54 編集
2019/11/21 16:14