Parcel: HMR failed in Electron

Created on 17 Dec 2017  路  2Comments  路  Source: parcel-bundler/parcel

Choose one: is this a 馃悰 bug report or 馃檵 feature request?
馃悰

馃帥 Configuration (.babelrc, package.json, cli command)


any

馃 Expected Behavior


HMR in electron's BrowserWindow

馃槸 Current Behavior



No HMR

馃拋 Possible Solution


I found the HMR init logic depends on the the module object. But the BrowserWindow in electron has its own window.module. That leads to the bug.
https://github.com/parcel-bundler/parcel/blob/b7b2991d69b960d9f2951828b8145a6d9396ee4e/src/builtins/hmr-runtime.js#L17

A temporary solution is setting nodeIntegration to false in BrowserWindow's options. But it removes some facilities in Electron. For someone indeed need node-integration, here may be a workaround: https://github.com/electron/electron/issues/5113 . However, I wish parcel could handle it.

馃敠 Context


Use parcel with Electron.

馃實 Your Environment

| Software | Version(s)
| ---------------- | ----------
| Parcel | 1.2.0
| Node | v8.9.3
| npm/Yarn | npm 5.6.0
| Operating System | mac 10.13.2

Bug

Most helpful comment

This solution from the Electron FAQ works. It also prevents the require('electron').xxx is undefined. issue:

https://electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron

Due to the Node.js integration of Electron, there are some extra symbols inserted into the DOM like module, exports, require. This causes problems for some libraries since they want to insert the symbols with the same names.

if you want to keep the abilities of using Node.js and Electron APIs, you have to rename the symbols in the page before including other libraries:

<head>
<script>
window.nodeRequire = require;
delete window.require;
delete window.exports;
delete window.module;
</script>
<script type="text/javascript" src="jquery.js"></script>
</head>

All 2 comments

This solution from the Electron FAQ works. It also prevents the require('electron').xxx is undefined. issue:

https://electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron

Due to the Node.js integration of Electron, there are some extra symbols inserted into the DOM like module, exports, require. This causes problems for some libraries since they want to insert the symbols with the same names.

if you want to keep the abilities of using Node.js and Electron APIs, you have to rename the symbols in the page before including other libraries:

<head>
<script>
window.nodeRequire = require;
delete window.require;
delete window.exports;
delete window.module;
</script>
<script type="text/javascript" src="jquery.js"></script>
</head>

Fixed with #652.

--target=electron

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidnagli picture davidnagli  路  3Comments

termhn picture termhn  路  3Comments

oliger picture oliger  路  3Comments

dotdash picture dotdash  路  3Comments

devongovett picture devongovett  路  3Comments