deno: Cannot import sqlite3 via npm and use it

I tried to import sqlite3 via npm. As shown below,

import sqlite from "npm:sqlite3";
console.log(sqlite);

 deno --unstable run -A tmp.ts

Then I got the following error.

error: Uncaught Error: Cannot find module '/Users/x/Library/Caches/deno/npm/registry.npmjs.org/sqlite3/5.0.11/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node'
Require stack:
- /Users/x/Library/Caches/deno/npm/registry.npmjs.org/sqlite3/5.0.11/lib/sqlite3-binding.js
- /Users/x/Library/Caches/deno/npm/registry.npmjs.org/sqlite3/5.0.11/lib/sqlite3.js
- /Users/x/Library/Caches/deno/npm/registry.npmjs.org/sqlite3/5.0.11/lib/sqlite3.js
    at Function.Module._resolveFilename (deno:ext/node/02_require.js:609:17)
    at Function.Module._load (deno:ext/node/02_require.js:441:29)
    at Module.require (deno:ext/node/02_require.js:652:21)
    at require (deno:ext/node/02_require.js:777:18)
    at Object.<anonymous> (file:///Users/x/Library/Caches/deno/npm/registry.npmjs.org/sqlite3/5.0.11/lib/sqlite3-binding.js:4:17)
    at Object.<anonymous> (file:///Users/x/Library/Caches/deno/npm/registry.npmjs.org/sqlite3/5.0.11/lib/sqlite3-binding.js:7:4)
    at Module._compile (deno:ext/node/02_require.js:713:36)
    at Object.Module._extensions..js (deno:ext/node/02_require.js:740:12)
    at Module.load (deno:ext/node/02_require.js:630:34)
    at Function.Module._load (deno:ext/node/02_require.js:487:14)

I am not sure if this is an error caused by the deno side or not. If anyone else is facing this problem, I would like to know the solution. Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (13 by maintainers)

Most upvoted comments

BTW if I hit the commant deno run npm:node-pre-gyp install --fallback-to-build manually in node_modules/sqlite3, the native addon (in my case lib/binding/napi-v6-darwin-unknown-x64/node_sqlite3.node) was correctly set up, and I was able to run deno run -A --node-modules-dir --unstable example.js in the root

Thanks for reporting @trgwii, it seems to be a regression that we missed. We’ll investigate and fix it.

Just to be sure, which OS did you check it on?

I just tried this issue with branch for https://github.com/denoland/deno/pull/13633 and the error is the same. I think this might be related to postinstall script or Node GYP

We don’t have node API support yet. Once this PR lands it will be possible: https://github.com/denoland/deno/pull/13633

Replacing install script with optionalDependencies with ‘os-arch’ suffix (like esbuild does https://github.com/evanw/esbuild/blob/50ae05ba9433c86ac227d917f3b92cec484ccfc5/npm/esbuild/package.json) might be a solution, but in that case it loses the support of minor platforms where prebuilt binaries are unavailable.

sqlite3 and other npm modules are implied to be FULLY working inside Deno without much effort on the part of the user on the 1.27 blog post. I just checked ALL of the modules listed there in Deno 1.28.1 with deno run --unstable -A --allow-ffi, and they ALL crash except for usb, which loads, but prints a bunch of debug messages about napi_add_finalizer not being supported.