diff --git a/keyserver/addons/rust-node-addon/index.js b/keyserver/addons/rust-node-addon/index.js --- a/keyserver/addons/rust-node-addon/index.js +++ b/keyserver/addons/rust-node-addon/index.js @@ -1,7 +1,14 @@ // @flow +import invariant from 'invariant'; +import { createRequire } from 'module'; + const { platform, arch } = process; +const importMetaURL = import.meta.url; +invariant(importMetaURL, 'import.meta.url should be set'); +const require = createRequire(importMetaURL); + type RustAPI = { +registerUser: ( userId: string, @@ -16,16 +23,16 @@ let nativeBinding = null; if (platform === 'darwin' && arch === 'x64') { // $FlowFixMe - nativeBinding = await import('./napi/rust-node-addon.darwin-x64.node'); + nativeBinding = require('./napi/rust-node-addon.darwin-x64.node'); } else if (platform === 'darwin' && arch === 'arm64') { // $FlowFixMe - nativeBinding = await import('./napi/rust-node-addon.darwin-arm64.node'); + nativeBinding = require('./napi/rust-node-addon.darwin-arm64.node'); } else if (platform === 'linux' && arch === 'x64') { // $FlowFixMe - nativeBinding = await import('./napi/rust-node-addon.linux-x64-gnu.node'); + nativeBinding = require('./napi/rust-node-addon.linux-x64-gnu.node'); } else if (platform === 'linux' && arch === 'arm64') { // $FlowFixMe - nativeBinding = await import('./napi/rust-node-addon.linux-arm64-gnu.node'); + nativeBinding = require('./napi/rust-node-addon.linux-arm64-gnu.node'); } else { throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`); } @@ -34,7 +41,7 @@ throw new Error('Failed to load native binding'); } - const { registerUser } = nativeBinding.default; + const { registerUser } = nativeBinding; return { registerUser }; } diff --git a/keyserver/addons/rust-node-addon/package.json b/keyserver/addons/rust-node-addon/package.json --- a/keyserver/addons/rust-node-addon/package.json +++ b/keyserver/addons/rust-node-addon/package.json @@ -22,6 +22,9 @@ } }, "license": "BSD-3-Clause", + "dependencies": { + "invariant": "^2.2.4" + }, "devDependencies": { "@napi-rs/cli": "^2.13.0" },