{"record":{"id":"b4a70b049f3b7294","repo":"can1357/oh-my-pi","slug":"unable-to-resolve-onnx-runtime-node-package-in","errorCode":null,"errorMessage":"Unable to resolve ${ONNX_RUNTIME_NODE_PACKAGE} in compiled runtime at ${nodeModules}","messagePattern":"Unable to resolve (.+?) in compiled runtime at (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/subprocess/worker-runtime.ts","lineNumber":242,"sourceCode":"\t\tthrow new Error(\n\t\t\t`Failed to install ONNX Runtime CUDA provider binaries into ${binDir} with ${process.execPath} ${script} (exit ${exitCode}). Remove the tiny-model side runtime cache at ${runtimeDir} and retry with network access. ${output}`,\n\t\t);\n\t}\n}\n\n/**\n * Repairs the compiled Transformers side runtime when CUDA was requested and\n * Bun skipped `onnxruntime-node`'s NuGet sidecar install.\n */\nexport async function ensureOnnxRuntimeCudaProviders(\n\truntimeDir: string,\n\tdevice = process.env.PI_TINY_DEVICE,\n): Promise<void> {\n\tif (!shouldInstallOnnxRuntimeCudaProviders(device)) return;\n\tconst nodeModules = path.join(runtimeDir, \"node_modules\");\n\tconst manifest = resolveRuntimeModule(nodeModules, `${ONNX_RUNTIME_NODE_PACKAGE}/package.json`);\n\tif (!manifest)\n\t\tthrow new Error(`Unable to resolve ${ONNX_RUNTIME_NODE_PACKAGE} in compiled runtime at ${nodeModules}`);\n\tconst packageDir = path.dirname(manifest);\n\tconst binDir = path.join(packageDir, LINUX_X64_ONNX_RUNTIME_CUDA_PROVIDER_DIR);\n\tconst missing = await missingOnnxRuntimeCudaProviderFiles(binDir);\n\tif (missing.length === 0) return;\n\n\tawait installOnnxRuntimeCudaProviders(packageDir, runtimeDir, binDir);\n\tconst stillMissing = await missingOnnxRuntimeCudaProviderFiles(binDir);\n\tif (stillMissing.length === 0) return;\n\tthrow new Error(\n\t\t`ONNX Runtime CUDA provider install completed but ${stillMissing.join(\", \")} are still missing from ${binDir}. Remove the tiny-model side runtime cache at ${runtimeDir} and retry.`,\n\t);\n}\n\n/**\n * Prepare a freshly-installed compiled runtime for loading and return the\n * absolute entrypoint of `packageName` to `require`.\n */\nasync function prepareCompiledRuntime(runtimeDir: string, packageName: string): Promise<string> {","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/subprocess/worker-runtime.ts#L224-L260","documentation":"Before repairing CUDA providers, ensureOnnxRuntimeCudaProviders resolves onnxruntime-node/package.json inside the compiled side runtime's node_modules. If the module cannot be resolved at all, the runtime cache is broken or incomplete and the function throws immediately rather than attempting an install.","triggerScenarios":"loadTransformersRuntime -> ensureOnnxRuntimeCudaProviders on linux x64 with PI_TINY_DEVICE=cuda/gpu/auto, when resolveRuntimeModule(runtimeDir/node_modules, 'onnxruntime-node/package.json') returns null — the package is absent from the extracted compiled runtime.","commonSituations":"Incomplete extraction of the compiled runtime archive, optional dependencies skipped during install (ONNXRUNTIME_NODE_INSTALL=skip or --no-optional), or the user manually deleted parts of the side-runtime cache.","solutions":["Delete the side runtime cache directory (runtimeDir) and relaunch so it is reinstalled from scratch.","Reinstall ensuring optional dependencies are included (do not pass --omit=optional / --no-optional).","Check that ONNXRUNTIME_NODE_INSTALL env var is not set to 'skip' in your environment.","Set PI_TINY_DEVICE=cpu if CUDA is unnecessary, bypassing this code path."],"exampleFix":"// before: side runtime missing onnxruntime-node\nruntimeDir/node_modules/  (no onnxruntime-node)\n// after\nrm -rf <runtimeDir> && omp   # reinstall includes onnxruntime-node","handlingStrategy":"validation","validationCode":"import { existsSync } from \"node:fs\";\nconst ok = existsSync(path.join(runtimeDir, \"node_modules\", \"onnxruntime-node\", \"package.json\"));\nif (!ok) await fs.rm(runtimeDir, { recursive: true, force: true }); // force clean reinstall first","typeGuard":null,"tryCatchPattern":"try {\n  await ensureOnnxRuntimeCudaProviders(runtimeDir, device);\n} catch (err) {\n  if (String(err.message).includes(\"Unable to resolve onnxruntime-node\")) {\n    await fs.rm(runtimeDir, { recursive: true, force: true });\n    // re-trigger runtime install, then retry once\n  } else throw err;\n}","preventionTips":["Never run installers with --omit=optional for the side runtime.","Wipe (not patch) a corrupted side-runtime cache.","Pin/upgrade onnxruntime-node as a pair with the host app version."],"tags":["onnx","module-resolution","side-runtime","cuda"],"backgroundTag":"module-not-found","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}