Help us understand the problem. What is going on with this article?

Electron で "cannot read property 'on' of undefined"と言われたときの対処

More than 3 years have passed since last update.

参考:require('electron') can be overridden by "electron" npm module

症状

Electronアプリを作成していて、実行すると"cannot read property 'on' of undefined"というエラーが出ることがある。
似たような症状として、"Cannot read property 'start' of undefined"という場合もあるようだ。

簡単な対処

理屈はいらないからなんとかしたい、というときは、

main.js
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;

となっているところを下記のように書き換えればいけると思う。

main.js
const electron = require('electron');
const app = electron.app || require('app');
const BrowserWindow = electron.BrowserWindow || require('browser-window');

原因

npm install electron とかやってるとなる(?)。
正しくは、npm install electron-prebuilt

正しい対処は、electronモデュールを削除することだと思われるが、削除がなかなかうまくできないこともあるようなので、上記の「簡単な対処」をするのが楽といえば楽。

JunSuzukiJapan
基本、未来の自分あてに備忘録として書いてます。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした