-
-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help me use Electron! #126
Comments
As a potentially helpful start to this thread, I'd like to contribute that many people have had their issues resolved by using @electron/rebuild. (Edit by @mceachen: |
I'm using both Electron and Windows so I'm happy to chime in here. I'm still using a custom fork but I think you resolved my PRs a while ago so I need to try master again. I'll let you know what we should document about Electron (at the very least, just like any native module, you do need to rebuild it for electron and electron-rebuild works great) |
@jlongster That's great, the help is much appreciated |
I,m still had this error even with electron rebuild here my package.json
OS: Linux Ubuntu Based |
I can help all our projects are using electron and better-sqlite3 this is our read me ///////////////////////////////////////////// npm install -g windows-build-tools(might need to install python and add the dir to the env file in windows) if that doesnt work install python 2.7 (not 3) then below to add to path. (windows 7 install .net 4.5.1) go (C:\Users%USERNAME%.windows-build-tools) BuildTools_Full.exe open BuildTools and click modify Check VC++ 2015.3 v14.00(v140) toolset for desktop npm install --save better-sqlite3 npm install --save-dev electron-rebuild go to terminal in the vs and run node_modules/.bin/electron-rebuild -f -w better-sqlite3 if you have more than one module that needs building like (bcypt) its best to use node_modules/.bin/electron-rebuild. |
It may be best to use nvm and set the same node version to match the version in electron... depending on what/how you are running functional/integration testing, you may still need the version against your framework outside electron. |
Hello, Searching throw stackoverflow it seems that the reason is that Electron's IPC only sends serializable object and Database is not (I'm not really sure about this). How can I pass the database from the main to the renderer? |
Where it doesn't work for you even with the
And there you go, you can run your app. |
@LucaPizzagalli You can't send database objects across IPC channels, but you can send a filename (string), which you can then use to open the same database within your renderer process. |
Would you clarify -- is it true that |
In my case which seems to basically be:
I have the feeling that node versions are involved, but absolutely no idea how to solve this. It may be related to the fact that when I run
Which is why I tried to run electron-rebuild in the first place. But no number of |
I had this problem once I built it with the wrong version. Delete your entire Node folder download electron first then better sqlite 3 then try and build. or it could be electron then electron rebuild then sqlite. |
so what we have done is we set up a worker file.. and the worker file will talk to the DB.. you should never run anything on the main thread.. as it causes a lock up on the clients PC. It took us a while to get this working properly XD. we use our main thread for only page changes and connections to the server. Everything else is run through our worker. |
I used the exact same command as barbalex and I received this error: https://gist.github.com/x-Aizawa/cff50adb7f9d4358e35b074a7b89dd42 It seems like the error is different than his/her so I haven't tried the solution provided by Custardcs. Any help would be appreciated. |
You need to install electron version 4.0.3, because since 4.0.4, no node version is high enough to fulfill the 69 version requirement. |
Im using version 4.0.4 without any issues |
can you give me a step by step example of what you have done.. from fresh project to here? so maybe i can help better |
I made an application and finished everything, decided to add SQLite to my application and those errors appear when installing/running app/using electron-rebuild. I'll try to downgrade the version for Electron. |
Show me your package.json, |
I see it says 'invalid file or disk full' you have enough space on your disk right? |
{
"name": "bank-account",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"author": "uBakkar",
"devDependencies": {
"electron": "^4.0.5",
"electron-rebuild": "^1.8.4"
},
"dependencies": {
"better-sqlite3": "^5.4.0",
"electron-reload": "^1.4.0",
"enmap": "^4.8.1",
"moment": "^2.24.0"
}
} Yes, I have 300GB free. |
@SwiTool - @Custardcs | I downgraded to v4.0.3 and this error appeared:
|
I'm still unable to upgrade to anything beyond Electron 19 because electron-rebuild is failing to rebuild better-sqlite3. I'm seeing the same errors @ilDon mentioned a year ago (#126 (comment)). I recently looked at this again and tried all of the current stable versions of Electron while running the same version of Node they use. Currently trying [email protected] with Node v18.15.0, @electron/[email protected], and [email protected]. Here are some error examples:
I've seen some related things around GitHub, but haven't found anything that works. One person thinks it's a bug in Node that needs to get resolved. I'm not sure where to go from here, other than to sit on Electron 19, which isn't supported anymore. Any ideas? Thanks in advance! |
Know that there are a ton of caches that may need to be blown away before you get an actual "clean" build. I've got this in my
|
So, on a vanilla I installed Ran electron, got the error as described. Added this to
Remember to add commas as appropriate to delimit the script lines. Error disappeared. Added a quick reference to a sqlite database and tested a quick write-read entry. Fully working! |
i get this error even with not using electron anywhere |
Hi. I'm having issues getting better-sqlite3 to work with my electron app. The installation was successful but keep getting this error on start.
I have tried quite a few suggestions to fix this including running I'll really appreciate any help here. Thanks. |
I'm trying to import When I add this: I get:
Using:
I tried several answers here without making it work. |
I had the same issue. I fixed it by externalizing 'better-sqlite3' in Vite's config: import { defineConfig } from "vite";
import builtInModules from "builtin-modules";
export default defineConfig({
build: {
// ...
rollupOptions: {
external: [...builtInModules, "electron", "better-sqlite3"],
// ...
},
},
}); |
Am I stupid? I can't find a node version that corresponds with NODE_MODULE_VERSION 113, as far as I can tell node 19 is 111 and node 20 is 115. electron-rebuild permutations are not working for me. This is using latest 9.1.1
|
@guspuffygit I'm not sure what exactly your goal is because according to that error, it's compiled for Electron Check these references: |
Thank you @m4heshd I figured it out. It was compiling correctly with the correct electron binaries. My issue was when running the jest test it was running jest with node (108) instead of electron which is where the error was happening. I was able to fix my issue by running jest using electron:
|
I have this error: How could I fix it? |
Does anyone have any instructions on how to install |
Answering my own question I found this very helpful in SO: |
I'm using esbuild, but not using electron. The solution for me was to add the following loader:
and the following to the esbuild config:
the bindings package is literally just a hardcoded list of different requires to try, and these days, in practice, it seems like it is sufficient to only look in |
I was constantly getting
And thus breaking Instead I decided to just manually load the bindings: import BetterSqlite3 from 'better-sqlite3'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const nativeBinding = require('better-sqlite3/build/Release/better_sqlite3.node') as string // technically an object but the nativeBinding field is typed as string | undefined
const client = new BetterSqlite3(':memory:', {
nativeBinding,
}) This also requires module: {
rules: [
{
test: /\.node$/,
loader: 'node-loader',
},
],
}, |
For anyone bundling with
Hope this helps. |
If you use Docker, then check out my solution. I solved it by installing |
Hello together, I'm new to Electron and vite and would like to get it running with sqlite3 or better-sqlite3. As I had many issues with sqlite3 due to either not compatible with vite in one version but also not compatible with eletron-builder with newer version I decided to use better-sqlite3 which basically solves some of my issues with vite and electron-builder Now I'm stucked at the point:
Hope someone here could help me get this running. This is my package.json {
"name": "electron-typescript-template",
"version": "0.0.1",
"description": "This is an electron typescript template",
"private": true,
"main": "./dist-electron/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc && vite build",
"start": "tsc && vite",
"dist": "electron-builder"
},
"author": "David",
"license": "UNLICENSED",
"devDependencies": {
"builtin-modules": "^3.3.0",
"electron": "^29.1.0",
"electron-builder": "^22.2.0",
"typescript": "^5.3.3",
"vite": "^5.1.4",
"vite-plugin-electron": "^0.28.2",
"vite-plugin-electron-renderer": "^0.14.5"
},
"build": {
"appId": "com.wanner.electron-typescript-template",
"files": [
"dist-electron",
"dist"
],
"mac": {
"category": "your.app.category.type"
},
"directories": {
"output": "build/Release/${version}"
}
},
"debug": {
"env": {
"VITE_DEV_SERVER_URL": "http://127.0.0.1:7777"
}
},
"dependencies": {
"@types/jquery": "^3.5.29",
"better-sqlite3": "^9.4.3",
"jquery": "^3.7.1"
}
} this is my vite.config.ts import { defineConfig } from 'vite';
import electron from 'vite-plugin-electron/simple'
import builtInModules from 'builtin-modules';
export default defineConfig({
plugins: [
electron({
main: {
// Shortcut of `build.lib.entry`
entry: 'app/electron/main.ts',
},
preload: {
// Shortcut of `build.rollupOptions.input`
input: 'app/electron/preload.ts',
},
// Optional: Use Node.js API in the Renderer process
renderer: {},
}),
],
}); adding the following lines to vite.config.ts doesn't solve my issue build: {
rollupOptions: {
external: [...builtInModules, "electron", "better-sqlite3"],
},
} For electron-builder I'm getting following issues: prebuild-install http 404 https://github.com/WiseLibs/better-sqlite3/releases/download/v9.4.3/better-sqlite3-v9.4.3-electron-v121-win32-x64.tar.gz
prebuild-install warn install No prebuilt binaries found (target=29.1.0 runtime=electron arch=x64 libc= platform=win32) |
Am using node I've had this issue in the past but can't remember how I fixed it. For some reason electron seems to be searching in the root of the project for the bindings, but the actual binding exists in
Have tried deleting node_modules and package-lock. Tried to configure the Copying the binding manually to the root folder does fix the issue, but it feels hacky and I'll need to do it dynamically for contributors using different architectures. Am more curious about the exact cause of the issue. Also, as a side note, this mega-thread is pretty awful for finding answers relevant to my specific problem. There are other issues which are more specific but they got closed in favour of this one, but it's full of tons of people with different problems and a bunch of them are hidden so it's difficult to find relevant solutions. I'd recommend allowing each specific error to exist as its own issue. |
I had no luck by directly running electron-rebuild. I had to change some build configurations. Inside package.json,
Now, run electron-rebuild. This will build better-sqlite3 from source for your electron and node versions. Build will take some time. So, second time change the configuration to :
This configuration will not build from source or download pre-built binary of better-sqlite3. It will take the binary from the first run of electron-rebuild. |
Did you find the root of this problem? I have a similar issue using Knex. I tried to use nativeBinding but it seems to ignore it. |
After I used Electron-builder to package and install the program, an error occurred during the program's operation:
What should I do? |
Putting this here in case it helps anyone struggling with electron-builder and better-sqlite3. My issue was better-sqlite3 was being built by the build machine on x64, even when I was trying to build for arm64. That gave me an x64 better-sqlite3 when I wanted an arm64 one. The solution was to:
To verify the fix I had to unpack the asars on mac, check the node_modules/better_sqlite3 and I compared the file size of the .node file for the x64 and arm64 builds. If the file size is different between arm64 and x64 builds you know it worked. Code is here: https://github.com/actualbudget/actual/pull/3220/files |
For the record, I highly recommend using electron forge (which is now officially supported and maintained by core electron team). That along with using Vite, marking better SQLite as external (like most node native addons must do). We have had great success! |
Ok wow I did it. Your message put me in the right direction thank you. My mistake was that I was editing vite.main.config.ts but I really needed to do that in vite.preload.config.ts in order to use sqlite with the contextBridge stuff from electron. import { defineConfig } from "vite";
// https://vitejs.dev/config
export default defineConfig({
build: {
rollupOptions: {
external: ["better-sqlite3"],
},
},
}); |
Electron Help Thread
This thread is for anyone who needs help using Electron with
better-sqlite3
.better-sqlite3
is a Node.js package, not an Electron package. If third parties like Electron decide to do fancy things that happen to break a perfectly functioning Node.js package, it is not an issue with that package. Any issues related to Electron should be reported here. If you're lucky, friendly members of the community may chime in here to help you.The text was updated successfully, but these errors were encountered: