{"record":{"id":"6de64f8b4b2f12d6","repo":"can1357/oh-my-pi","slug":"cannot-find-module-onnxruntime-node-windows-dll-fo","errorCode":null,"errorMessage":"Cannot find module onnxruntime-node Windows DLL for ${arch} beside ${ortEntry}","messagePattern":"Cannot find module onnxruntime-node Windows DLL for (.+?) beside (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mnemopi/src/core/fastembed-runtime.ts","lineNumber":100,"sourceCode":"\tarch = process.arch,\n\tenv = process.env,\n}: WindowsFastembedRuntimeOptions): Promise<WindowsFastembedRuntime> {\n\tconst nestedNodeModules = path.join(fastembedPackageDir, \"node_modules\");\n\tconst rootNodeModules = path.dirname(fastembedPackageDir);\n\tconst nestedOrtEntry = resolveRuntimeModule(nestedNodeModules, \"onnxruntime-node\");\n\tconst ortEntry = nestedOrtEntry ?? resolveRuntimeModule(rootNodeModules, \"onnxruntime-node\");\n\tconst ortPackageDir = path.join(nestedOrtEntry ? nestedNodeModules : rootNodeModules, \"onnxruntime-node\");\n\tif (!ortEntry) {\n\t\tthrow new Error(`Cannot find module onnxruntime-node beside ${fastembedEntry}`);\n\t}\n\tconst dllGlob = new Bun.Glob(`bin/napi-*/win32/${arch}/onnxruntime.dll`);\n\tlet dllDir: string | undefined;\n\tfor await (const dll of dllGlob.scan({ cwd: ortPackageDir, absolute: true, onlyFiles: true })) {\n\t\tdllDir = path.dirname(dll);\n\t\tbreak;\n\t}\n\tif (!dllDir) {\n\t\tthrow new Error(`Cannot find module onnxruntime-node Windows DLL for ${arch} beside ${ortEntry}`);\n\t}\n\n\tconst currentPath = env.PATH;\n\tconst normalizedDllDir = path.resolve(dllDir).toLowerCase();\n\tconst alreadyPresent = currentPath\n\t\t?.split(path.delimiter)\n\t\t.some(entry => path.resolve(entry).toLowerCase() === normalizedDllDir);\n\tif (!alreadyPresent) env.PATH = currentPath ? `${dllDir}${path.delimiter}${currentPath}` : dllDir;\n\treturn { ortEntry, ortPackageDir, dllDir };\n}\n\nexport function loadFastembed(): Promise<FastembedModule> {\n\tfastembedLoad ??= loadFastembedOnce().catch(error => {\n\t\tfastembedLoad = null;\n\t\tthrow error;\n\t});\n\treturn fastembedLoad;\n}","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/core/fastembed-runtime.ts#L82-L118","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Delete the fastembed runtime cache / node_modules and reinstall so onnxruntime-node postinstall re-downloads the native DLL for the current arch","Verify the DLL exists at <onnxruntime-node>/bin/napi-v6/win32/<arch>/onnxruntime.dll (or napi-v3 variant); if missing, reinstall onnxruntime-node","Confirm process.arch matches the installed onnxruntime-node platform binaries (install the matching package variant for arm64/x64)","Ensure bun install is allowed to run trustedDependencies postinstall scripts for onnxruntime-node"],"exampleFix":"// before (corrupted install)\nnode_modules/onnxruntime-node/bin/napi-v6/win32/x64/  // empty\n// after\n$ rm -rf ~/.cache/.../fastembed-* node_modules/onnxruntime-node\n$ bun install","handlingStrategy":"fallback","validationCode":"import { existsSync } from \"node:fs\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\nfunction ortDllPresent(): boolean {\n  const req = createRequire(import.meta.url);\n  let ortDir: string;\n  try { ortDir = path.dirname(req.resolve(\"onnxruntime-node/package.json\")); } catch { return false; }\n  const dll = path.join(ortDir, \"bin\", \"napi-v6\", \"win32\", process.arch, \"onnxruntime.dll\");\n  return process.platform !== \"win32\" || existsSync(dll);\n}","typeGuard":"function isWindowsOrtRuntimeReady(r: { dllDir?: string } | null): r is { dllDir: string } {\n  return r !== null && typeof r.dllDir === \"string\" && r.dllDir.length > 0;\n}","tryCatchPattern":"try {\n  await loadFastembed();\n} catch (err) {\n  if (String(err).includes(\"Windows DLL\")) {\n    logger.warn(\"onnxruntime native DLL missing; falling back to remote embeddings\", { err });\n  } else throw err;\n}","preventionTips":["Pre-warm the fastembed runtime cache during install, not first use","Never strip onnxruntime-node native assets from packaged/bundled distributions","Verify arch-specific binaries exist when cross-building Windows artifacts","Keep onnxruntime-node in trustedDependencies so its postinstall can fetch DLLs"],"tags":["windows","native-module","onnxruntime","fastembed"],"backgroundTag":"native-dll-not-found","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}