Skip to content
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

SqliteError: The specified module could not be found on Windows #526

Closed
yuis-ice opened this issue Jan 2, 2021 · 9 comments
Closed

SqliteError: The specified module could not be found on Windows #526

yuis-ice opened this issue Jan 2, 2021 · 9 comments

Comments

@yuis-ice
Copy link

yuis-ice commented Jan 2, 2021

I'd like to use SQLite extension for Regexp.

Firstly I tried using the extension on WSL Linux bash on Windows, I'm on Windows. Run sudo apt update ; sudo apt-get install sqlite3 sqlite3-pcre -y and the same code as below worked well on it.

But I'm working on Electron, this is working good on Windows, and from Powershell, so I wanted to use the extension from Windows side.

The locally installed packages are like this:

  "dependencies": {
    "better-sqlite3": "^7.1.2",
    "electron": "^11.1.1",
    "electron-rebuild": "^2.3.4",
    "nodemon": "^2.0.6",
    "sleep": "^6.3.0",
    "sqlite3": "^5.0.0"
  }

Then, I copied the extension file from WSL path /usr/lib/sqlite3/pcre.so to local Windows path ./pcre.so.
Now the environment is the same as the Linux one, right? So I run the code.

index.js

const Database = require('better-sqlite3');
const db = new Database('../../node/note_system_tmp.db', { verbose: console.log });

db.loadExtension('./pcre.so');

// more ..

But this time I got an error as below.

Full error

SqliteError: The specified module could not be found.

    at Object.<anonymous> (C:\pg\electron\note_system_ui\index.js:29:4)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12738)
    at loadApplicationPackage (C:\pg\electron\note_system_ui\node_modules\electron\dist\resources\default_app.asar\main.js:110:16)
    at Object.<anonymous> (C:\pg\electron\note_system_ui\node_modules\electron\dist\resources\default_app.asar\main.js:222:9)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10)

So, I could use the extension file on Linux, now on Windows, how can I load and use extensions? I need your help, I appreciate your help. Thanks.

@Prinzhorn
Copy link
Contributor

Prinzhorn commented Jan 2, 2021

pcre.so is compiled for Linux. On Windows it should be something like pcre.dll. If I understand correctly you copied the file between operating systems? That does not work.

If you want to avoid all the trouble you can define the regexp user function in JavaScript https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#functionname-options-function---this

@Masoud-kamali
Copy link

I used .dll format, but the same error has been shown.

@yuis-ice
Copy link
Author

yuis-ice commented Jan 2, 2021

thanks, I understand that. I'm not familiar to C so I'll try compiling the extension to .dll (not .so) later and see if works well.

@yuis-ice
Copy link
Author

yuis-ice commented Jan 3, 2021

I have question, SQLite is working on node.js, then why I need to have a operation system compatible extension file for that? Since I googled a lot and couldn't find a precompiled extension and way to compile the .c program to .dll, I cannot think implementing this regex feature is this hard and barely no information around the internet. Also, I find a way to load extension within the SQL, like this below, isn't this works for .c program since not depends on the operation system? Thanks for your help.

SELECT load_extension('/usr/lib/sqlite3/pcre.so');

@Masoud-kamali
Copy link

Masoud-kamali commented Jan 3, 2021

Also, I use

SELECT load_extension('mod_spatialite');

in cmd and it works, but we have this error in this library and particularly NodeJs. I searched a lot of pages, but all solution talk about difference between 32bit and 64 bit of nodejs and this extension. Also, I downloaded both 32bit and 64bit version and tried the other solution, but they works for python not nodejs and this library.
I think it's the question of lots of people around the world !!!

@yuis-ice
Copy link
Author

yuis-ice commented Jan 3, 2021

thanks for the info.
Since I installed WSL 2 and tried to run Electron directly from WSL bash, it didn't work for this so I decided that I don't use Electron(so, also Windows) and use better-sqlite3 on Linux WSL as a CLI tool so no worry for this error. Said that I'm still curious about the solution for this, I'll keep this issue open for now.

@JoshuaWise
Copy link
Member

Any updates on this issue?

@yuis-ice
Copy link
Author

yuis-ice commented May 5, 2021

No updates. you can close the issue if you want to.

@tanin47
Copy link

tanin47 commented Jul 6, 2021

I've encountered this problem and managed to resolve it.

For my situation, the root cause is that better-sqlite3 only offers a binary for x64, but the default cl.exe is for x86. The DLL compiled with the x86 cl.exe will not work.

What is even more confusing is that https://sqlite.org/download.html only offers a binary for x86. So, if we compile with the default cl.exe, it'll work with Sqlite CLI but not better-sqlite3.

What we need to do is to switch the cl.exe from x86 to x64 by running "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" first.

I'm using better-sqlite3 with Electron successfully (see: https://superintendent.app), so if you have any question, Please let me know. I hope you are unblocked by my answer.

For reference, my compilation command is: cl something.c -I . -link -dll -out:something.dll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants