{"record":{"id":"7ef3a00bf8b6c677","repo":"can1357/oh-my-pi","slug":"cannot-find-module-onnxruntime-node-beside-faste","errorCode":null,"errorMessage":"Cannot find module onnxruntime-node beside ${fastembedEntry}","messagePattern":"Cannot find module onnxruntime-node beside (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/mnemopi/src/core/fastembed-runtime.ts","lineNumber":91,"sourceCode":"/**\n * Prepend the ORT DLL directory paired with fastembed before Bun loads its\n * native binding. Compiled Windows binaries extract `.node` files to a\n * temporary directory, so the default DLL search can otherwise select an\n * unrelated `onnxruntime.dll` from the inherited system path.\n */\nexport async function prepareWindowsFastembedRuntime({\n\tfastembedEntry,\n\tfastembedPackageDir,\n\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 };","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/core/fastembed-runtime.ts#L73-L109","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install onnxruntime-node explicitly alongside fastembed (`bun add onnxruntime-node`) so it is resolvable.","Re-install dependencies without --omit=optional / --no-optional so the optional native dep lands in node_modules.","For bundled/compiled apps, ship node_modules/onnxruntime-node next to fastembed (or set the path layout the resolver expects: fastembedPackageDir/../node_modules).","With pnpm, hoist onnxruntime-node (`public-hoist-pattern`) or add it as a direct dependency to fix resolution."],"exampleFix":"// before\nbun add fastembed  # onnxruntime-node optional dep skipped on this CI image\n// after\nbun add fastembed onnxruntime-node  # ensure ONNX runtime is present","handlingStrategy":"validation","validationCode":"import { $which } from \"@oh-my-pi/pi-utils\"; // or manual resolution\nconst ort = path.join(process.cwd(), \"node_modules\", \"onnxruntime-node\");\nif (!(await Bun.file(ort).exists())) {\n  throw new Error(\"onnxruntime-node not installed: run `bun add onnxruntime-node`\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await prepareWindowsFastembedRuntime(fastembedEntry);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Cannot find module onnxruntime-node\")) {\n    // print setup instructions: install onnxruntime-node / unbundle native deps\n  } else throw e;\n}","preventionTips":["Add onnxruntime-node as a direct dependency, not an implicit optional one.","Never install with --omit=optional in environments that use fastembed.","For compiled/bundled apps, include node_modules/onnxruntime-node as an external asset and smoke-test startup on Windows CI.","Check the resolved layout (fastembed's own node_modules or its parent) after switching package managers."],"tags":["windows","onnx","native-module","module-resolution","fastembed"],"backgroundTag":"missing-native-dependency","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}