Skip to content

Using better-sqlite3 in a global CLI causes errors. #1015

Open
@broccolihighkicks

Description

@broccolihighkicks

I have a Node.js CLI that I am developing that is installed with npm install --global my-cli

This is in my package.json:

"bin": {
    "my-cli": "dist/cli.js"
}

The issue is that when my-cli is run, it is run with from the current working directory where it is called.

better-sqlite3 seems to try to read the SQLite compiled lib based on the current working directory, causing it to fail with these errors:

1. Error: Could not find module root given file: "node:internal/modules/cjs/loader". Do you have a `package.json` file?
2. Error: Could not locate the bindings file. Tried:

I have a temporary work around where I set the current working directory before new Database and then restore it afterwards.

What is the correct config for a global CLI that uses better-sqlite3?

Also, how are prebuilt binaries used? On an M1 it seems to build SQLite from source, is this normal?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions