7

On a Window 10 Home (on x64 bit), I tried running the following command on a Command Prompt:

node index.js

The error was the following:

C:\Users\cooldudeasateen\OneDrive\Coding\sil\node_modules\bindings\bindings.js:121 throw e; ^

Error: \?\C:\Users\cooldudeasateen\OneDrive\Coding\sil\node_modules\better-sqlite3\build\Release\better_sqlite3.node is not a valid Win32 application. \?\C:\Users\humay\OneDrive\Coding\sil\node_modules\better-sqlite3\build\Release\better_sqlite3.node at Object.Module._extensions..node (node:internal/modules/cjs/loader:1183:18) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:94:18) at bindings (C:\Users\cooldudeasateen\OneDrive\Coding\sil\node_modules\bindings\bindings.js:112:48) at Object. (C:\Users\cooldudeasateen\OneDrive\Coding\sil\node_modules\better-sqlite3\lib\database.js:9:24) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:94:18) at Object. (C:\Users\cooldudeasateen\OneDrive\Coding\sil\node_modules\better-sqlite3\lib\index.js:2:18) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) { code: 'ERR_DLOPEN_FAILED' }

I'm using the following Node version: v16.6.2

3 Answers 3

6

Now I don't need help, the problem was that I installed x86 instead of x64, which was an honest mistake.

How did I know that I made this mistake? Well, honestly, I looked at other files of other version of Nodejs, and it ended in x64 instead of x86. Honestly, it was my mistake and I should've looked at them before installing new Nodejs version.

2
  • 4
    Thanks for sharing your answer: You can also type node -p "process.arch" to determine if 64 bit.
    – dylanh724
    Commented Aug 10, 2022 at 4:43
  • @dylanh724 It show me "x64". I used node version 14.18 to build index.node. when electron requre it throw "not Win32 application"
    – mqliutie
    Commented May 11, 2024 at 2:58
5

For me I had to remove the node_modules folder and re-run npm install. Most likely because there was some issue when I first installed packages ...

I also made sure my node is x64 using node -p "process.arch" as mentioned in the comment.

2
  • 1
    I was looking for this node -p "process.arch", thanks man Node V16.14.0 has only x32 and there is no x64, changed the version with x64 and it worked Commented May 12, 2023 at 10:48
  • My pc's arch show me x64, but the index.node show me error in electron..
    – mqliutie
    Commented May 11, 2024 at 3:00
  • A follow-up discussion was started:
    “developing vscode extension on arm64 and I get warning: crypt32.node is not a valid Win32 application; how to get rid of warning?” Join the conversation
4

Many node modules are just JavaScript and are portable across systems. Some, however, contain native compiled code. The SQLite library you are using is not 'pure JavaScript' and relies on a binary.

When you npm install-ed it installed a binary for the system you were using at that time, for example, you were on a Mac. The better_sqlite3.node file was for that specific operating system.

You then opened this project on a different computer but also copied over the node_modules directory. Just like how you can't run .app files on Windows or (usually) .exe on Linux, this binary is not compatible with your OS. Removing and then re-installing the SQLite library will install a Windows-compatible binary.

Since your project is in a OneDrive folder, it might be that you are switching between operating systems. That could make this process tedious. One workaround would be to install the SQLite module globally, but that has some drawbacks.

require() will look not just through the current directory, but also recursively directories above it (eg ...\OneDrive\Coding\sil, then ...\OneDrive\Coding, then ...\OneDrive), before checking the global directory.

1
  • The thing is that I did not switch OS. Another point is that I use nodejs v14 to update to v16, plus I used the same version of Window 10, same architecture and same bit. Commented Aug 12, 2021 at 13:33

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.