質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Electron

Electronは、HTML5とNode.jsというWebの技術を用いてデスクトップアプリケーションを作成できるクロスプラットフォームな実行環境です。

npm

npmは、Node Packaged Modulesの略。Node.jsのライブラリ・パッケージを管理できるツールです。様々なモジュールを簡単にインストールでき、自分でモジュールを作成し公開する際にも使用できます。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Q&A

解決済

1回答

1933閲覧

electronのレンダラープロセスでエラーが発生する(require使用時)

y-ymo10

総合スコア6

Electron

Electronは、HTML5とNode.jsというWebの技術を用いてデスクトップアプリケーションを作成できるクロスプラットフォームな実行環境です。

npm

npmは、Node Packaged Modulesの略。Node.jsのライブラリ・パッケージを管理できるツールです。様々なモジュールを簡単にインストールでき、自分でモジュールを作成し公開する際にも使用できます。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

0グッド

0クリップ

投稿2019/11/21 14:29

ソースコードとエラーコード

###レンダラープロセス
レンダラープロセスのデベロッパーツールでエラーが表示されました。
エラー内容から、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

情報が少ないですが、どなたか解決用方法を教えていただけらたら幸いです。
よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

CoffeeScript をトランスパイルせずに JavaScript として読み込もうとしたのが原因です。

このエラーを出なくするだけであれば、CoffeeScript をトランスパイルしてファイルを置き換えればいいですが、完全に対症療法なのでおすすめできません。
ビルド手順を間違えているのが根本的な原因である可能性が高いので、そちらをどうにかしたほうがいいです。
そして、この質問の仕方とエラー内容から考えるに、十中八九質問者の作ったプログラムではないのでしょう。
このプログラムを作った人に聞くか、ドキュメントがあるならそれを読んでください。

投稿2019/11/21 15:32

2KOH

総合スコア999

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

y-ymo10

2019/11/21 15:46

回答ありがとうございます。 すみません、私が作ったものではありますが、node.jsのアプリ以外の開発をしていたもので、electronはあまり詳しくない状態でWindowを簡易的に作成できる様作成しました。 一度CoffeeScriptに対するエラーの対応を行ってみます。
2KOH

2019/11/21 15:54 編集

エラー原因の CoffeeScript は、remote という Node.js のパッケージに含まれているファイルのようです。 このパッケージを調べたところ、7年前から更新されていないようです。 CoffeeScript に対処するよりも、このパッケージを使わないようにする方がいいと思います。
y-ymo10

2019/11/21 16:14

回答ありがとうございます。 CoffeeSc ripのエラーが解決しました。 別のエラーが出てしまったので、そちらに専念したいと思います。 別のエラーでわからないことがあったら改めて質問をしたいと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問