Skip to content

Commit d2523b8

Browse files
committed
fix: adapt deviceId import to cjs and esm
1 parent d28b29c commit d2523b8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/helpers/deviceId.ts

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

5+
// Import node-machine-id based on the module system
6+
67
export const DEVICE_ID_TIMEOUT = 3000;
78

89
export class DeviceId {
@@ -17,7 +18,11 @@ export class DeviceId {
1718
private constructor(logger: LoggerBase, timeout: number = DEVICE_ID_TIMEOUT) {
1819
this.logger = logger;
1920
this.timeout = timeout;
20-
this.getMachineId = (): Promise<string> => nodeMachineId.machineId(true);
21+
this.getMachineId = async (): Promise<string> => {
22+
const nodeMachineId = await import("node-machine-id");
23+
const machineId = nodeMachineId.default?.machineId || nodeMachineId.machineId;
24+
return machineId(true);
25+
};
2126
this.abortController = new AbortController();
2227

2328
this.deviceIdPromise = DeviceId.UnknownDeviceId;

0 commit comments

Comments
 (0)