Restart (`rs`) and the Webpack plugin do not work with a native module
See original GitHub issuePre-flight checklist
- I have read the contribution documentation for this project.
- I agree to follow the code of conduct that this project uses.
- I have searched the issue tracker for a bug that matches the one I want to file, without success.
Electron Forge version
6.0.0-beta.67
Electron version
v20.1.1
Operating system
Windows 10 Version 21H1 Build 19043.2130
Last known working Electron Forge version
No response
Expected behavior
I have better_sqlite3
included in my project, which is based on the Webpack+Typescript template.
npm start
works fine, and so does npm run package
– after either of these I can access the SQLite API.
It should also work when I restart it using rs
as mentioned here:
If you type rs (and hit enter) in the same terminal where you ran the start command, the running app will be terminated and restarted.
Forge plugins can override this command to run custom development logic. For example, the Webpack Plugin runs a webpack-dev-server instance to provide live reloading and HMR.
Actual behavior
I get an error message when I type rs
as follows:
Steps to reproduce
FYI the git commit I made to include better-sqlite3 in my project is here …
… but it was easy to do, nothing special, i.e.:
- Install
better-sqlite3
as a run-time dependency - Install the latest Node.js with the “Windows build tools” option enabled so that it can be built for Electron
- Include it in the Main process using
import sqlite from 'better-sqlite3';
Additional information
It finds better_sqlite3.node
when it starts but not when it restarts.
The error message says it’s looking for undefinedbuild/Release/better_sqlite3.node
In fact the better_sqlite3.node
exists in the following directories:
C:\Users\Christopher\Source\Repos\pic>dir /s better_sqlite3.node
Volume in drive C is Windows
Volume Serial Number is 6EBC-4C1A
Directory of C:\Users\Christopher\Source\Repos\pic\.webpack\main\native_modules\build\Release
05/11/2022 18:29 2,659,328 better_sqlite3.node
1 File(s) 2,659,328 bytes
Directory of C:\Users\Christopher\Source\Repos\pic\node_modules\better-sqlite3\build\Release
23/10/2022 09:41 2,659,328 better_sqlite3.node
1 File(s) 2,659,328 bytes
Directory of C:\Users\Christopher\Source\Repos\pic\out\pic-win32-x64\resources\app\.webpack\main\native_modules\build\Release
29/10/2022 09:52 2,659,328 better_sqlite3.node
1 File(s) 2,659,328 bytes
Total Files Listed:
3 File(s) 7,977,984 bytes
The one which it’s successfully using when it starts is presumably the one in the .webpack\main\native_modules\
directory – and this is the path fragment that’s replaced with "undefined"
during a restart.
I see there are previous issues related to rs
– https://github.com/electron/forge/issues?q=rs – but they’re all close.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
I tested this on latest forge (inited from template, added depedency, etc.)
Had to drop to Electron 19 because that module doesn’t support Electron 20 or higher yet (https://github.com/WiseLibs/better-sqlite3/pull/870) but other than that it works fine during both start, restart and package
The problem is this line of code:
That TypeScript statement translates to this JavaScript:
When I press
rs
without modifying the code, the value of__webpack_require__.ab
(on my machine) is'C:\Users\Christopher\Source\Repos\pic\.webpack\main/native_modules/'
And it’s undefined when I have the problem on restart.
Maybe it’s related to this, because that’s to do with setting the
__webpack_require__.ab
value:IOW maybe the
@vercel/webpack-asset-relocator-loader
is not being re-run or something.I can work-around the problem using their
nativeBinding
option which is described here:So for example if my code looks like this then I don’t get the error:
That’s not ideal, especially when the application is packaged (but a useful work-around to make
rs
work).In summary I guess this problem related to the
@vercel/webpack-asset-relocator-loader
is not being re-run on restart.