DallasHoff / sqlocal

SQLocal makes it easy to run SQLite3 in the browser, backed by the origin private file system.
https://sqlocal.dallashoffman.com
MIT License
212 stars 8 forks source link

ERR_MODULE_NOT_FOUND when compiling for Node.js #22

Closed Quacken8 closed 4 months ago

Quacken8 commented 4 months ago

There is some issue with importing drizzle (possibly related to #1?) image

I have tried both "moduleResolution": "bundler" and "moduleResolution": "nodenext" as well as

    "paths": {
      "sqlocal/*": ["../node_modules/sqlocal/dist/*"]
    }

I also tried the minimal hello world example from your other repo, however to compile it I had to remove "noEmit": true and "allowImportingTsExtensions": true the problem persists :

➜  sqlocal-drizzle-hello-world git:(main) ✗ node src/main.js 

node:internal/modules/esm/resolve:264
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/ondra/Documents/sqlocal-drizzle-hello-world/node_modules/.pnpm/sqlocal@0.5.2/node_modules/sqlocal/dist/drizzle/client' imported from /home/ondra/Documents/sqlocal-drizzle-hello-world/node_modules/.pnpm/sqlocal@0.5.2/node_modules/sqlocal/dist/drizzle/index.js
    at finalizeResolution (node:internal/modules/esm/resolve:264:11)
    at moduleResolve (node:internal/modules/esm/resolve:917:10)
    at defaultResolve (node:internal/modules/esm/resolve:1130:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///home/ondra/Documents/sqlocal-drizzle-hello-world/node_modules/.pnpm/sqlocal@0.5.2/node_modules/sqlocal/dist/drizzle/client'
}

Node.js v20.11.1
Quacken8 commented 4 months ago

Vite does let me build the project, however I'd love to use SQLocal in projects that use fs and other node modules that cannot be built for the browser

DallasHoff commented 4 months ago

Am I correct in understanding that you are trying to run SQLocal in Node.js? SQLocal is for running a SQLite database in the browser. It does not work on the server side.

Quacken8 commented 4 months ago

I'm trying to use sqlite in a vscode extension and those run in node. Most sqlite solutions use native modules which may create issues with compatibility and since sqlocal builds to wasm I hoped it would be a better option

DallasHoff commented 4 months ago

SQLite WASM does not support Node.js since its storage mechanism is implemented with the Origin Private File System API, which is not supported by Node.js. I think SQLite WASM may be working on a second storage implementation with Node.js support, but for now, it's a browser-only solution.

Depending on what your VSCode extension is meant to do, you may still be able to use SQLocal as long as you do it in a context where the code is being run by VSCode's Chromium engine, not Node.js, such as in a webview.