diff --git a/node/native.js b/node/native.js index b5fd160e..d3afd658 100644 --- a/node/native.js +++ b/node/native.js @@ -12,26 +12,25 @@ // See the License for the specific language governing permissions and // limitations under the License. -const { currentTarget } = require('@neon-rs/load'); +const { currentTarget } = require('@neon-rs/load') -let nativeLib; +let nativeLib try { - nativeLib = require(`@lancedb/vectordb-${currentTarget()}`); -} catch (e) { - try { - // Might be developing locally, so try that. But don't expose that error - // to the user. - nativeLib = require("./index.node"); - } catch { - throw new Error(`vectordb: failed to load native library. + // When developing locally, give preference to the local built library + nativeLib = require('./index.node') +} catch { + try { + nativeLib = require(`@lancedb/vectordb-${currentTarget()}`) + } catch (e) { + throw new Error(`vectordb: failed to load native library. You may need to run \`npm install @lancedb/vectordb-${currentTarget()}\`. If that does not work, please file a bug report at https://github.com/lancedb/lancedb/issues - Source error: ${e}`); - } + Source error: ${e}`) + } } // Dynamic require for runtime. -module.exports = nativeLib; +module.exports = nativeLib diff --git a/node/package.json b/node/package.json index 5165815c..6a382db2 100644 --- a/node/package.json +++ b/node/package.json @@ -9,7 +9,7 @@ "build": "cargo-cp-artifact --artifact cdylib vectordb-node index.node -- cargo build --message-format=json", "build-release": "npm run build -- --release", "test": "npm run tsc && mocha -recursive dist/test", - "lint": "eslint src --ext .js,.ts", + "lint": "eslint native.js src --ext .js,.ts", "clean": "rm -rf node_modules *.node dist/", "pack-build": "neon pack-build", "check-npm": "printenv && which node && which npm && npm --version"