Better-sqlite3: From macOS Catalina to Windows 10, "better_sqlite3.node is not a valid win32 application"

Created on 17 Dec 2020  路  5Comments  路  Source: JoshuaWise/better-sqlite3

I'm attempting to go mobile with my development so I'm not stuck at home all the time, and I've cloned my repository to a windows laptop from my mac. On mac everything is peachy, but when I attempt to run on windows I get the above error.

Is there something I need to adjust in order for better-sqlite3 to operate cross-platform? This isn't a build, it's just running the project with npm start command. I'm on version 7.1.1, I saw elsewhere that this problem might be fixed in v7. Is it still in the works? More importantly, if I build the app with this version, will it work on windows?

help wanted

All 5 comments

I've cloned my repository to a windows laptop from my mac

This isn't a build, it's just running the project with npm start command

These two sentences contradict, unless you've checked node_modules into your repository, which you should never do.

If I understand correctly you are trying to run code compiled for Mac on Windows, that doesn't work.

I need to adjust in order for better-sqlite3 to operate cross-platform

You need to build better-sqlite3 on each platform, it's a native dependency.

Thank you! Let me make sure I understand this, because I'm intermediate at best with all of this but trying to learn fast:

On each machine, I need to install the node_modules independently. It sounds like I may need to install them globally? That way the project itself doesn't have its own node_modules folder, but the package.json can still match, right? But the module for better-sqlite3 that each machine is referencing is built for that machine (as well any other nodes I'm using).

When I push to repo, then, I'm just including the code for the project itself, not any of the associated nodes. If this is the case, normally I believe I'm supposed to .gitignore the package-lock.json, but should I include it as well? I'm not trying to run compiled code--if I understand properly what compiled code means; this is still human readable, it's the project source folders/files opened in Atom in my case.

I realize this must seem entirely basic to anyone who does this professionally, I'm not there yet. So thank you for indulging what must seem painfully simple.

It sounds like I may need to install them globally?

What do you mean by globally? In general the only thing you install globally are command line tools that you want to use on your PC independent of a project. E.g. npm install -g localtunnel.

normally I believe I'm supposed to .gitignore the package-lock.json, but should I include it as well?

No, you need to .gitignore node_modules/ and definitely need to check package-lock.json into git. Because package-lock.json makes sure that everywhere you npm install you get the exact same version of all packages (while package.json can specify ranges and also doesn't contain all of the recursive dependencies that each of the package has). So if you only have package.json in your project and you git clone && npm install on a different machine or even the productions server you might end up with different versions of packages (e.g. because there was an update in the mean time) which potentially can break your system.

if I understand properly what compiled code means; this is still human readable, it's the project source folders/files opened in Atom in my case.

When you run npm install you download external packages into node_modules/. And in the case of better-sqlite3 it's a native package. That means it doesn't contain only JavaScript, it's written in C++. And hence it needs to be compiled to machine code for the current architecture and operating system. That's why you can't just copy node_modules/ to a different machine. Which _could_ work if you wouldn't have any native dependencies because everything would be JavaScript and could be run without compiling it first (but it's more complicated than that, because even a pure JavaScript module could use a postinstall script to do platform specific configurations). So never move node_modules/ anywhere.

Okay, I think I understand:

  1. On the mac, gitignore the node_modules folder, but _include_ package-lock.json.
  2. On windows, clone the repo (which will include package-lock but won't include node_modules)
  3. On windows, npm install the relevant nodes. (and make sure that better-sqlite3 is built with c++14, if I recall from another thread on getting it working on windows). Gitignore should ignore node_modules from windows as well.
  4. Ergo, do the same on any other machine, for instance if I'm going to test the app on a *nix system as well.

UPDATE: That got it running on windows! Thank you so much for helping me out with that, I really appreciate it.

When/if it comes time to compile the app, I take it this means I'll need to compile the .dmg/mac version on mac, compile the .exe/windows version on windows, and any *nix version on that machine. Is that correct?

I know this has strayed off topic. If I've got that correct, we can close this.

When/if it comes time to compile the app, I take it this means I'll need to compile the .dmg/mac version on mac, compile the .exe/windows version on windows, and any *nix version on that machine. Is that correct?

Yes.

Closing this as it seems to be resolved

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DrDonkeyPunch picture DrDonkeyPunch  路  5Comments

spiffytech picture spiffytech  路  5Comments

k1ngrnbz picture k1ngrnbz  路  4Comments

Babalon921 picture Babalon921  路  3Comments

eslachance picture eslachance  路  3Comments