can1357/oh-my-pi · error · Error

Cannot find module onnxruntime-node Windows DLL for ${arch}

Error message

Cannot find module onnxruntime-node Windows DLL for ${arch} beside ${ortEntry}

What it means

prepareWindowsFastembedRuntime locates the onnxruntime-node native DLL (bin/napi-*/win32/<arch>/onnxruntime.dll) inside fastembed's own onnxruntime-node dependency and prepends its directory to PATH so Windows loads the paired DLL. It throws this error when the onnxruntime-node package resolves but contains no DLL matching the requested architecture, meaning the native asset directory is missing, empty, or was pruned (e.g. by an installer or package cache that excludes large binaries).

Source

Thrown at packages/mnemopi/src/core/fastembed-runtime.ts:100

	arch = process.arch,
	env = process.env,
}: WindowsFastembedRuntimeOptions): Promise<WindowsFastembedRuntime> {
	const nestedNodeModules = path.join(fastembedPackageDir, "node_modules");
	const rootNodeModules = path.dirname(fastembedPackageDir);
	const nestedOrtEntry = resolveRuntimeModule(nestedNodeModules, "onnxruntime-node");
	const ortEntry = nestedOrtEntry ?? resolveRuntimeModule(rootNodeModules, "onnxruntime-node");
	const ortPackageDir = path.join(nestedOrtEntry ? nestedNodeModules : rootNodeModules, "onnxruntime-node");
	if (!ortEntry) {
		throw new Error(`Cannot find module onnxruntime-node beside ${fastembedEntry}`);
	}
	const dllGlob = new Bun.Glob(`bin/napi-*/win32/${arch}/onnxruntime.dll`);
	let dllDir: string | undefined;
	for await (const dll of dllGlob.scan({ cwd: ortPackageDir, absolute: true, onlyFiles: true })) {
		dllDir = path.dirname(dll);
		break;
	}
	if (!dllDir) {
		throw new Error(`Cannot find module onnxruntime-node Windows DLL for ${arch} beside ${ortEntry}`);
	}

	const currentPath = env.PATH;
	const normalizedDllDir = path.resolve(dllDir).toLowerCase();
	const alreadyPresent = currentPath
		?.split(path.delimiter)
		.some(entry => path.resolve(entry).toLowerCase() === normalizedDllDir);
	if (!alreadyPresent) env.PATH = currentPath ? `${dllDir}${path.delimiter}${currentPath}` : dllDir;
	return { ortEntry, ortPackageDir, dllDir };
}

export function loadFastembed(): Promise<FastembedModule> {
	fastembedLoad ??= loadFastembedOnce().catch(error => {
		fastembedLoad = null;
		throw error;
	});
	return fastembedLoad;
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Delete the fastembed runtime cache / node_modules and reinstall so onnxruntime-node postinstall re-downloads the native DLL for the current arch
  2. Verify the DLL exists at <onnxruntime-node>/bin/napi-v6/win32/<arch>/onnxruntime.dll (or napi-v3 variant); if missing, reinstall onnxruntime-node
  3. Confirm process.arch matches the installed onnxruntime-node platform binaries (install the matching package variant for arm64/x64)
  4. Ensure bun install is allowed to run trustedDependencies postinstall scripts for onnxruntime-node

Example fix

// before (corrupted install)
node_modules/onnxruntime-node/bin/napi-v6/win32/x64/  // empty
// after
$ rm -rf ~/.cache/.../fastembed-* node_modules/onnxruntime-node
$ bun install
Defensive patterns

Strategy: fallback

Validate before calling

import { existsSync } from "node:fs";
import * as path from "node:path";
import { createRequire } from "node:module";
function ortDllPresent(): boolean {
  const req = createRequire(import.meta.url);
  let ortDir: string;
  try { ortDir = path.dirname(req.resolve("onnxruntime-node/package.json")); } catch { return false; }
  const dll = path.join(ortDir, "bin", "napi-v6", "win32", process.arch, "onnxruntime.dll");
  return process.platform !== "win32" || existsSync(dll);
}

Type guard

function isWindowsOrtRuntimeReady(r: { dllDir?: string } | null): r is { dllDir: string } {
  return r !== null && typeof r.dllDir === "string" && r.dllDir.length > 0;
}

Try / catch

try {
  await loadFastembed();
} catch (err) {
  if (String(err).includes("Windows DLL")) {
    logger.warn("onnxruntime native DLL missing; falling back to remote embeddings", { err });
  } else throw err;
}

Prevention

When it happens

Trigger: Calling loadFastembed/loadResolvedFastembed on Windows (process.platform === 'win32') when the resolved onnxruntime-node package directory under fastembed's dependency graph lacks a file matching glob bin/napi-*/win32/${arch}/onnxruntime.dll — e.g. arch mismatch (arm64 vs x64 install), an install that skipped postinstall downloads, or a corrupted/partial node_modules.

Common situations: Running a Bun-compiled Windows binary whose onnxruntime-node package was installed with scripts disabled; copying node_modules across machines/architectures; a proxy or antivirus stripping the ~200MB native assets; using an x64 build on ARM64 Windows without the x64 emulation DLLs present.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/6de64f8b4b2f12d6. Report an issue: GitHub.