LoginSignup
3
7

More than 5 years have passed since last update.

webpackでelectronを使う時にはまったこと

Last updated at Posted at 2016-12-14

この前から構築してたgulp環境上でelectronアプリ作ろうと思って、とりあえず公式のクイックスタートでもやってみるかって思ってやったらどん詰まりした。

起動すると

TypeError: Cannot read property 'on' of undefined
    at Object.<anonymous> (/Users/…/dist/js/client-bundle.js:75:5)
    at Object.<anonymous> (/Users/…/dist/js/client-bundle.js:88:31)
    at __webpack_require__ (/Users/…/dist/js/client-bundle.js:20:30)
    at /Users/…/dist/js/client-bundle.js:40:18
    at Object.<anonymous> (/Users/…/dist/js/client-bundle.js:43:10)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)

とかいう感じで怒られた。

importやrequire等、読み込み方をかえてみたりしたけど全然読み込めない。

解決

調べてみたらwebpackにはelectronをtargetとするコンパイルにするってオプションが存在しててそれを書いたら行けた。

export default {
  output: {
    filename: 'client-bundle.js',
  },
// 省略
  target: 'electron', // ←これ
};
3
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
7