ソースコードとエラーコード
レンダラープロセス
エラーになるところは下記のソースコードの
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'; //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: '' }); } 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 }, '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': true, webPreferences: { nodeIntegration: false } }); 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(){ var wns = new window_ejs('Menu'); wns.width=500; wns.height=500; wns.Drow("ejs"); });
状態
electronを実行したところ、レンダラープロセスのコンソールでエラーコードが表示されている状態です。
エラーメッセージ
Uncaught ReferenceError: require is not defined at Menu.ejs:12
情報が少ないですが、どなたか情報をいただけますと助かります。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/11/19 03:19
2019/11/19 07:37
2019/11/20 09:01
2019/11/20 15:58
2019/11/21 03:36
2019/11/21 10:28
2019/11/21 14:09