react-scripts test
runs on Node and my app runs on Electron's compiled version of Node.
Thus I get the classic error:
The module '.../better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 103. This version of Node.js requires
NODE_MODULE_VERSION 93. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
This has been partly addressed here: https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules
But here is the problem: If I run npm rebuild
, react-scripts test
starts working but I can't run my app. If I run electron-rebuild
, my app starts up but react-scripts test
stops working.
It's a pain to have to keep running these 2 different commands based on what I am trying to do.
How do people fix this issue?
I did this workaround:
"scripts": {
"test": "npm rebuild && react-scripts test",
"run": "electron-rebuild && electron .",
}