I can't get my Railway image working with better-sqlite3

jconsani03
TRIAL

a year ago

The problem I have is that, when deploying, I get an error with the better-sqlite3 module and according to my research it is because it creates a different .bin depending on the OS. I am currently using Windows and everything works fine locally, so I assume that the Railway image will be on another OS (Unix-based) and that is why I get an error. I tried setting the following "npm run install" as the initial deploy command (from the options Railway gives me), to install the dependencies from Railway itself. However, this does not work for me and I keep getting the same error.

ERROR:

node:internal/modules/cjs/loader:1460

return process.dlopen(module, path.toNamespacedPath(filename));

Error: /app/nodemodules/better-sqlite3/build/Release/bettersqlite3.node: invalid ELF header

at Module._extensions..node (node:internal/modules/cjs/loader:1460:18)

at Module.load (node:internal/modules/cjs/loader:1203:32)

at Module._load (node:internal/modules/cjs/loader:1019:12)

at Module.require (node:internal/modules/cjs/loader:1231:19)

at require (node:internal/modules/helpers:177:18)

at bindings (/app/node_modules/bindings/bindings.js:112:48)

at new Database (/app/node_modules/better-sqlite3/lib/database.js:48:64)

at [file:///app/src/models/Usuarios.js:3:12](file:///app/src/models/Usuarios.js:3:12)

at [ModuleJob.run](ModuleJob.run) (node:internal/modules/esm/module_job:195:25)

at async ModuleLoader.import (node:internal/modules/esm/loader:337:24) {

code: 'ERRDLOPENFAILED'

}

Node.js v18.20.2

0 Replies

jconsani03
TRIAL

a year ago

4e72106d-15ff-4034-85a1-90640c0ddb4e


a year ago

are you commiting your node_modules folder to github?


jconsani03
TRIAL

a year ago

I've solved the problem. It turns out that the better-sqlite3 module is compiled depending on the OS, unlike most modules that are backwards compatible with different OS. I simply specified within the start script that the module should be installed before execution, so that the Linux version would be installed and not the Windows one (which is the OS I have).


a year ago

that sound more like a round about fix because you where committing your node_modules?


jconsani03
TRIAL

a year ago

yep


I can't get my Railway image working with better-sqlite3 - Railway Help Station