Skip to content

Commit 1264ab2

Browse files
authored
fix: adapt deviceId import to cjs and esm (#491)
1 parent a06b443 commit 1264ab2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/helpers/deviceId.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { getDeviceId } from "@mongodb-js/device-id";
2-
import * as nodeMachineId from "node-machine-id";
32
import type { LoggerBase } from "../common/logger.js";
43
import { LogId } from "../common/logger.js";
54

@@ -17,7 +16,11 @@ export class DeviceId {
1716
private constructor(logger: LoggerBase, timeout: number = DEVICE_ID_TIMEOUT) {
1817
this.logger = logger;
1918
this.timeout = timeout;
20-
this.getMachineId = (): Promise<string> => nodeMachineId.machineId(true);
19+
this.getMachineId = async (): Promise<string> => {
20+
const nodeMachineId = await import("node-machine-id");
21+
const machineId = nodeMachineId.default?.machineId || nodeMachineId.machineId;
22+
return machineId(true);
23+
};
2124
this.abortController = new AbortController();
2225

2326
this.deviceIdPromise = DeviceId.UnknownDeviceId;

0 commit comments

Comments
 (0)