can1357/oh-my-pi · critical · Error

Cannot find module onnxruntime-node beside ${fastembedEntry}

Error message

Cannot find module onnxruntime-node beside ${fastembedEntry}

What it means

prepareWindowsFastembedRuntime locates the onnxruntime-node native module by checking node_modules nested inside the fastembed package, then the parent root. If neither resolves, it throws because fastembed cannot load its ONNX backend (needed to place the Windows DLL directory).

Source

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

/**
 * Prepend the ORT DLL directory paired with fastembed before Bun loads its
 * native binding. Compiled Windows binaries extract `.node` files to a
 * temporary directory, so the default DLL search can otherwise select an
 * unrelated `onnxruntime.dll` from the inherited system path.
 */
export async function prepareWindowsFastembedRuntime({
	fastembedEntry,
	fastembedPackageDir,
	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 };

View on GitHub (pinned to 9690622007)

Solutions

  1. Install onnxruntime-node explicitly alongside fastembed (`bun add onnxruntime-node`) so it is resolvable.
  2. Re-install dependencies without --omit=optional / --no-optional so the optional native dep lands in node_modules.
  3. For bundled/compiled apps, ship node_modules/onnxruntime-node next to fastembed (or set the path layout the resolver expects: fastembedPackageDir/../node_modules).
  4. With pnpm, hoist onnxruntime-node (`public-hoist-pattern`) or add it as a direct dependency to fix resolution.

Example fix

// before
bun add fastembed  # onnxruntime-node optional dep skipped on this CI image
// after
bun add fastembed onnxruntime-node  # ensure ONNX runtime is present
Defensive patterns

Strategy: validation

Validate before calling

import { $which } from "@oh-my-pi/pi-utils"; // or manual resolution
const ort = path.join(process.cwd(), "node_modules", "onnxruntime-node");
if (!(await Bun.file(ort).exists())) {
  throw new Error("onnxruntime-node not installed: run `bun add onnxruntime-node`");
}

Try / catch

try {
  await prepareWindowsFastembedRuntime(fastembedEntry);
} catch (e) {
  if (e instanceof Error && e.message.startsWith("Cannot find module onnxruntime-node")) {
    // print setup instructions: install onnxruntime-node / unbundle native deps
  } else throw e;
}

Prevention

When it happens

Trigger: Running fastembed on Windows when onnxruntime-node is not installed (optional dependency skipped), or in bundled/compiled/pnpm-layout setups where the package directory structure differs from a standard npm tree.

Common situations: Installing with `--omit=optional` (onnxruntime-node is an optional dep), bun compile/single-file builds dropping native modules, pnpm's symlinked layout hiding the expected sibling relationship, or a partial install.

Related errors


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