Repository navigation
fix: npm install fails on Windows with Node 24+ (better-sqlite3 native build) - #14
Conversation
…e build) better-sqlite3 11.10.0 ships win32 prebuilds only for Node ABI 108-131 (Node 18-23). On Node 24 LTS/25/26 npm falls back to node-gyp, which needs Visual Studio Build Tools, so the global install fails. - better-sqlite3 ^11.10.0 -> ^12.11.1 (win32/darwin/linux prebuilds for Node 22/24/25/26), moved to optionalDependencies. - Lazy-load it via src/lib/sqlite.ts so a missing module only affects local clone/push, not every command (index.ts loads local.ts eagerly). - engines.node >=18 -> >=22. - Windows smoke test: Node matrix [22, 24, 26]; assert the native module installed and loads; assert the CLI starts without it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sh --with-db - Windows smoke: fail if better-sqlite3 has build/config.gypi. The runner has Visual Studio, so a missing prebuild would otherwise compile silently and pass while users without build tools fail. - local push --with-db: check the native module before syncing files, so a missing module can't fail after files are pushed and an overwrite prompt. - Error message names Node 26; rename the install step (no native deps now). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
…codebase Type-only rename; the compiled dist/lib/sqlite.js is byte-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
Ready at adf2270. QA PASS at 4239e5b, 40efcfe and adf2270 (clone with/without the SQLite binary, npm 12, Node 24). Windows CI green on adf2270 (Node 22/24/26). Code review PASS on all rounds. |
… to fix it npm 12 blocks install scripts by default, so a global install keeps the better-sqlite3 package but never downloads its binary. require() still succeeds; the first `new Database()` throws a raw "Could not locate the bindings file". loadSqlite() now opens an in-memory DB once so that case gets the friendly message, which names --allow-scripts=better-sqlite3. `instawp upgrade` passes the flag (npm 10/11 accept it), and the README install command includes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| # the native build fails. That must never happen on a supported Node | ||
| # version — load it from the global install and open a DB to prove it. | ||
| $cli = Join-Path (npm root -g) "@instawp\cli" | ||
| node -e "const D=require(require.resolve('better-sqlite3',{paths:[process.argv[1]]}));const db=new D(':memory:');console.log('better-sqlite3', db.prepare('select sqlite_version() v').get().v);db.close()" $cli |
There was a problem hiding this comment.
BUG: Wrong process.argv index — should be process.argv[2], not process.argv[1]
When running node -e "script" $cli, the Node process receives:
process.argv[0]='node'process.argv[1]= the-escript stringprocess.argv[2]=$cli(the CLI path)
The code uses process.argv[1] which is the script itself, not the argument. This works by accident because require.resolve falls back to default resolution, but it's incorrect.
| node -e "const D=require(require.resolve('better-sqlite3',{paths:[process.argv[1]]}));const db=new D(':memory:');console.log('better-sqlite3', db.prepare('select sqlite_version() v').get().v);db.close()" $cli | |
| node -e "const D=require(require.resolve('better-sqlite3',{paths:[process.argv[2]]}));const db=new D(':memory:');console.log('better-sqlite3', db.prepare('select sqlite_version() v').get().v);db.close()" $cli |
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
|
QA: PASS ✅ · Env: Linux x64 QA host, throwaway sandbox
Repro-before-fix: yes. The beta.33 row reproduces the user's bug on Linux, and the PR fixes all of it. — QA |
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (10 files)
Fix these issues in Kilo Cloud Previous Review Summaries (2 snapshots, latest commit 8d995b8)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 8d995b8)Status: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (6 files)
Fix these issues in Kilo Cloud Previous review (commit 4239e5b)Status: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (9 files)
Issue Details1. 2. Reviewed by nemotron-3-ultra-550b-a55b:free · Input: 537.6K · Output: 12K · Cached: 829.4K |
…qlite3 12.x, optional + lazy-loaded) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
… CI install; accurate npm 11 comment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lure message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
QA: PASS ✅ · Env: Linux x64 QA host, throwaway sandbox
Answer to the clone question: yes, it is still true. Without bs3, — QA |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
…a plain success without the DB Before, a missing better-sqlite3 (npm 12 without --allow-scripts) made the DB import fail on one easily-missed line and the command still ended with a green "Clone complete!" over an empty site. Now clone checks the module right after resolving the site (try/catch, warns, continues), and if the import failed for any reason the completion header says so and why. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
QA: PASS ✅ · Env: Linux x64 QA host, Node 24.21.0 + npm 12.2.0, throwaway sandbox
Answers: 1) yes / yes / yes / exit 0. 2) unchanged: green, DB imported with the right content. 3) Two non-blocking wording points:
— QA |
Problem
npm install -g @instawp/clifails on Windows for anyone on Node 24 LTS, 25 or 26. The log ends withnpm warn cleanup Failed to remove some directories, which is npm rolling back after a native build error.Root cause
better-sqlite3^11.10.0 resolves to 11.10.0, which ships prebuilt Windows binaries only for Node ABI 108/115/127/131 (Node 18–23).node-gyp, which needs Visual Studio Build Tools. Most users don't have them, so the whole install fails.local.tsimported it statically andindex.tsloadslocal.tsat startup, so a missing module also broke every command,loginincluded.Change
better-sqlite3^11.10.0 → ^12.11.1, the newest 12.x on npm (12.12.0 exists only as a GitHub tag). It has prebuilds for Node 22/24/25/26 on win32/darwin/linux, x64 and arm64. It is now an optionalDependency, so a failed native build no longer fails the install.src/lib/sqlite.ts→loadSqlite()loads it on first use (createRequire, so callers stay synchronous). The static imports inlocal.tsandsqlite-to-mysql.tsare nowimport type. If the module is missing, onlylocal cloneandlocal push --with-dbfail, with a message saying how to fix it.push --with-dbchecks this before syncing any files.engines.node>=18→>=22(12.11.1 has no Node 20 prebuild, and Node 18/20 are EOL). README, CLAUDE.md and the publish job are updated to match.publish.ymlWindows smoke test:[22, 24, 26];build/config.gypiexists, meaning it was compiled from source (the runner has Visual Studio, so a missing prebuild would otherwise pass silently);Evidence
tscclean; vitest 254/254.api-exec.test.tsfails to load in the agent sandbox onmaintoo.node_modules/better-sqlite3hidden,main'sinstawp --versioncrashes withERR_MODULE_NOT_FOUND, and this branch exits 0.workflow_dispatch, publish job skipped), this branch @ 4139494: Node 22 / 24 / 26 all green. That covers the native module installing from a prebuild, loading, and the CLI starting with it hidden. Run: https://github.com/InstaWP/cli/actions/runs/37922379716npm ci(the source build fails). This reproduces the user's bug and proves the new check catches it. Run: https://github.com/InstaWP/cli/actions/runs/37922383215BetterSqlite3→Database); the compileddist/lib/sqlite.jsis byte-identical. CI was re-dispatched on it anyway.local push --with-dbpreflight are applied.Not in this PR
No version bump or release. Cutting
0.0.1-beta.34is a separate tag push.ClickUp: https://app.clickup.com/t/14ypaj0hnkn
Agentric session: https://aos.agents.instawp.net/#/sessions/aos-ses_8ef4990541280f46
Next step (human):
/code-review ultra <PR#>before merge.— Engineer (agent-os)
🤖 Generated with Claude Code