claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Cannot find package 'better-sqlite3'

Open AnthonyRonning opened this issue 1 year ago • 62 comments

Just updated 5 minutes ago, doesn't launch anymore....

Environment

  • Platform (select one):
    • Anthropic API
  • Claude CLI version: no clue, errors out
  • Operating System: ubuntu 24.04 nix
  • Terminal: tmux

Bug Description

claude
node:internal/modules/esm/resolve:854
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'better-sqlite3' imported from /home/tony/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js
    at packageResolve (node:internal/modules/esm/resolve:854:9)
    at moduleResolve (node:internal/modules/esm/resolve:927:18)
    at defaultResolve (node:internal/modules/esm/resolve:1169:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v20.15.1

Steps to Reproduce

  1. Update
  2. Launch claude

Expected Behavior

It should work

Actual Behavior

It doesnt work


Official workaround (via @bcherny ):

npm install -g @anthropic-ai/[email protected]

Older, unofficial workarounds

Install globally (via @10-X-eng ):

npm -g install better-sqlite3

Or install locally if your claude is in ~/.claude/local` (via @josh-gree ):

cd ~/.claude/local
npm install better-sqlite3

AnthonyRonning avatar Apr 25 '25 17:04 AnthonyRonning

Just came here to write the same thing. Give this a whirl

npm install better-sqlite3

10-X-eng avatar Apr 25 '25 17:04 10-X-eng

FIx isnt working :( ran the command and same issue

benny-yamagata avatar Apr 25 '25 17:04 benny-yamagata

Should be: npm -g install better-sqlite3 which works but I wouldn't expect to have to install an external dependency.

AnthonyRonning avatar Apr 25 '25 17:04 AnthonyRonning

That doesn't work either - its installation isn't global anymore they changed this at some point - it installs in ~ /.claude/local now :-(

can fix by doing;

cd ~/.claude/local
npm install better-sqlite3

josh-gree avatar Apr 25 '25 17:04 josh-gree

Yup, just updated and am experiencing this as well!

imsahsol avatar Apr 25 '25 17:04 imsahsol

FIx isnt working :( ran the command and same issue

Strange. worked fine for me. hence why i posted it.

10-X-eng avatar Apr 25 '25 17:04 10-X-eng

I had to upgrade to latest lts of node.

Node.js v22.15.0 $ npm install -g better-sqlite3

now all is good.

markpollack avatar Apr 25 '25 17:04 markpollack

Sorry about that! Pushed a bad release.

We just unpublished 0.2.83. Please manually downgrade to fix:

npm install -g @anthropic-ai/[email protected]

bcherny avatar Apr 25 '25 17:04 bcherny

@bcherny how does this work with the change in installation that was rolled out previously - wasn't that done to remove the global install?

There was a / command "fix install" or something right?

josh-gree avatar Apr 25 '25 17:04 josh-gree

Yes, you'll need to re-run /migrate-installer after, if you ran it previously. Sorry about that!

bcherny avatar Apr 25 '25 17:04 bcherny

After downgrading and uninstalling better-sqlite3 (for those above that installed it), I can confirm it works again.

npm uninstall -g better-sqlite3

AnthonyRonning avatar Apr 25 '25 17:04 AnthonyRonning

honestly its reassuring when even the big guys accidentally push crap to prod. makes me feel better.

cahaseler avatar Apr 25 '25 17:04 cahaseler

Should be: npm -g install better-sqlite3 which works but I wouldn't expect to have to install an external dependency.

This work on MacOS 15.3.2

Zoomelectrico avatar Apr 25 '25 17:04 Zoomelectrico

it worked, but it then automatically installed the bad update again and broke as soon as I restarted the tool.

cahaseler avatar Apr 25 '25 17:04 cahaseler

We shouldn't need to install 'better-sqlite3' globally for claude to work. That should be a dependency the project is responsible to install.

andrewdavid48 avatar Apr 25 '25 17:04 andrewdavid48

We shouldn't need to install 'better-sqlite3' globally for claude to work. That should be a dependency the project is responsible to install.

I think they agree, they accidentally broke it is all.

cahaseler avatar Apr 25 '25 17:04 cahaseler

We shouldn't need to install 'better-sqlite3' globally for claude to work. That should be a dependency the project is responsible to install.

I think they agree, they accidentally broke it is all.

Agreed. I'm not throwing blame, just pointing out that npm i -g should not be the solution, even for a temporary fix.

If anything, it's safest to just run a previous version, e.g.: npx @anthropic-ai/[email protected]

andrewdavid48 avatar Apr 25 '25 17:04 andrewdavid48

it worked, but it then automatically installed the bad update again and broke as soon as I restarted the tool.

@cahaseler the new version is unpublished, so it might be an NPM cache or something. Try again?

bcherny avatar Apr 25 '25 17:04 bcherny

I'm stuck with this same exact issue.

· Computing… (2460s · ⚒ 19.5k tokens · esc to interrupt)

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ >                                                                                                                                                                                                    │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
  ⏵⏵ auto-accept edits on (shift+tab to toggle)                                                                                                                  ✓ Update installed · Restart to apply

and then boom, everything is broke!

% claude
node:internal/modules/package_json_reader:268
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'better-sqlite3' imported from /Users/user/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:268:9)
    at packageResolve (node:internal/modules/esm/resolve:768:81)
    at moduleResolve (node:internal/modules/esm/resolve:854:18)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:685:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:634:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:617:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:273:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:135:49) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v22.14.0

FWIW, I'm on macOS 15.3.2 (24D81), node v22.14.0, npm at 10.9.2

msmygit avatar Apr 25 '25 18:04 msmygit

fwiw, I also got below warnings in between and I deleted the prefix files too,

Your user’s .npmrc file (${HOME}/.npmrc)
has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.
Run `nvm use --delete-prefix v22.14.0 --silent` to unset it.

no luck, nothing works. I tried to npm install -g @anthropic-ai/claude-code and still the same error.

msmygit avatar Apr 25 '25 18:04 msmygit