'Cannot find module '/home/container/node_modules/sqlite3/lib/binding/napi-v3-linux-x64/node_sqlite3.node'

Everything's running perfectly throught cmd on my pc but when i host it on my host servers i have this error:

`:/home/container$ npm start knexfile.js Starting Modmail 3.3.0 on Node.js 12.19.1 (x64) Loading configuration from config.ini... Configuration ok! Using an SQLite database: /home/container/db/data.sqlite Knex: run $ npm install sqlite3 --save Cannot find module '/home/container/node_modules/sqlite3/lib/binding/napi-v3-linux-x64/node_sqlite3.node' Require stack:

  • /home/container/node_modules/sqlite3/lib/sqlite3-binding.js
  • /home/container/node_modules/sqlite3/lib/sqlite3.js
  • /home/container/node_modules/knex/lib/dialects/sqlite3/index.js
  • /home/container/node_modules/knex/lib/knex.js
  • /home/container/node_modules/knex/lib/index.js
  • /home/container/node_modules/knex/knex.js
  • /home/container/src/knex.js
  • /home/container/src/main.js
  • /home/container/src/index.js`


Solution 1:[1]

SQLite3 needs a library which is specific for the architecture of your target system. If you install the npm package, it tries to build this library from its source code, "live" on the target machine. This may fail, if the target system does not have the necessary C compiler and build tools installed.

If you try to upload your node_modules folder to the target machine, this does only work, if dev and prod machines have the same architecture. So uploading the modules from your dev machine (Windows) to the target machine (Linux) will not work in your scenario.

One solution would be to install all necessary build tools on the target machine, delete the node_modules/sqlite3 folder and retry package installation with npm install.

A workaround would be to compile the necessary Linux library on a different Linux machine or an equivalent docker container and then upload it to the target machine.

The file for Linux AMD64 architecture can be found in this folder after a successful npm install: node_modules/sqlite3/lib/binding/napi-v3-linux-x64

If none of the above is an option for you, you will find a version for [email protected] which I compiled right now at http://hosting134516.a2e37.netcup.net/napi-v3-linux-x64/node_sqlite3.node but please observe, that this may only work with version 5.0.2 of the SQLite3.

Greeting, Alex

Solution 2:[2]

RESOLVED: I had a yarn.locker file in my project. I deleted that file and rebuild the project and it worked for me. Steps:

  1. Delete yarn.locker
  2. docker build
  3. docker run

The error may be because of previous downloaded dependencies which are not compatible.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexander Schmitt
Solution 2 Akshay Jain