Issue trying to commit using visual studio code in-build source control tool

After updating couchbase node js sdk from v3 to v4 we discovered that there was an issue when trying to commit to github using visual studio code’s in-build source control tool. (committing from terminal was working fine)
We are using husky to run unit tests before commit and this is the error we received:

Error: Could not find native build for platform=darwin, arch=arm64, runtime=electron, nodeVersion=18.18.2, sslType=boringssl loaded from /Users/X/Desktop/XXX/node_modules/couchbase.
    at resolvePrebuild (/Users/X/Desktop/XXX/node_modules/couchbase/scripts/prebuilds.js:456:9)
    at Object.loadPrebuild (/Users/X/Desktop/XXX/node_modules/couchbase/scripts/prebuilds.js:331:25)
    at Object.<anonymous> (/Users/X/Desktop/XXX/node_modules/couchbase/dist/binding.js:166:41)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/Users/X/Desktop/XXX/node_modules/couchbase/dist/couchbase.js:21:35)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/Users/X/Desktop/XXX/lib/CouchbaseManager.js:2:19)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/Users/X/Desktop/XXX/tests/unit/CouchbaseManager.test.js:4:26)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
husky - pre-commit hook exited with code 1 (error)

I suspected that it happened because of “runtime=electron”.

Also, I am not sure if this helps, but I had a look at “couchbase/scripts/prebuilds.js” and in the “resolvePrebuild” function there is following code:

  const _runtime = useElectronRuntime
    ? 'electron'
    : runtime === 'node'
    ? 'napi'
    : runtime

runtime === 'node' looked wrong to me so I changed the code to:

  const _runtime = useElectronRuntime
    ? 'electron'
    : 'node'
    ? 'napi'
    : runtime

and after this change I was able to commit using vs code in-build source control tool.

Hi @iraklitchedia – VS code use the electron runtime, so if husky is not doing anything in particular to make sure it uses the node runtime then it makes sense the SDK will not be able to find its binary. I think there are 2 work-arounds:

  • You should be able to change the package.json test script to use the package runner (npx), so something like "test": "npx ts-mocha" or "test": "npx vitest run"
  • You can point the environment variable CN_PREBUILD_PATH_OVERRIDE to the path of your prebuild (should be in node_modules/@couchbase/)

I hope this helps.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.