mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 04:42:10 +03:00
fix(machineToken): use require() for node-machine-id to survive webpack bundling
The default import + destructuring pattern was being mangled by webpack's static analysis during Next.js standalone builds, causing 'Cannot destructure property machineIdSync of undefined' errors in production. Using require() bypasses webpack's interop wrapper (c.n(...)) and loads the module's exports directly at runtime.
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import { createHmac } from "node:crypto";
|
||||
import nodeMachineId from "node-machine-id";
|
||||
|
||||
const { machineIdSync } = nodeMachineId;
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
let machineIdSync: (original?: boolean) => string;
|
||||
try {
|
||||
// Use require() to bypass webpack static analysis that breaks the default export
|
||||
const mod = require("node-machine-id");
|
||||
machineIdSync = mod.machineIdSync || mod.default?.machineIdSync;
|
||||
} catch {
|
||||
machineIdSync = () => "";
|
||||
}
|
||||
|
||||
const BUILTIN_DEFAULT_SALT = "omniroute-cli-auth-v1";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user