{"record":{"id":"5ac1073d34135483","repo":"ruvnet/ruflo","slug":"aidefence-package-not-available-install-with-npm","errorCode":null,"errorMessage":"AIDefence package not available. Install with: npm install @claude-flow/aidefence","messagePattern":"AIDefence package not available\\. Install with: npm install @claude-flow/aidefence","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/mcp-tools/security-tools.ts","lineNumber":75,"sourceCode":"    const aidefence = await import(packageName);\n    const instance = aidefence.createAIDefence({ enableLearning: true });\n    if (!instance) {\n      throw new Error('createAIDefence returned null');\n    }\n    aidefenceInstance = instance;\n    return instance;\n  } catch (e) {\n    // Package not found or failed to load\n    const error = e as Error;\n    if (!error.message?.includes('Cannot find package') && !error.message?.includes('ERR_MODULE_NOT_FOUND')) {\n      // Different error - might be a real issue\n      throw new Error(`AIDefence failed to load: ${error.message}`);\n    }\n  }\n\n  // Don't attempt install more than once per session\n  if (installAttempted) {\n    throw new Error('AIDefence package not available. Install with: npm install @claude-flow/aidefence');\n  }\n  installAttempted = true;\n\n  // Second attempt - auto-install and retry\n  console.error(`[claude-flow] ${packageName} not found, attempting auto-install...`);\n  const installed = await autoInstallPackage(packageName);\n\n  if (!installed) {\n    throw new Error('AIDefence package not available. Install with: npm install @claude-flow/aidefence');\n  }\n\n  // #1807 — auto-install lands the package somewhere Node's standard\n  // resolver couldn't find on the FIRST attempt (npm-global installs are\n  // a common offender). Try Node's resolver again first (it may have\n  // picked up the new node_modules directory), then fall back to the\n  // file:// + cache-bust import dance, then surface a clearly actionable\n  // error if everything still fails.\n  // Plain re-import (covers project-local installs that landed where Node","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/mcp-tools/security-tools.ts#L57-L93","documentation":"Error \"AIDefence package not available. Install with: npm install @claude-flow/aidefence\" thrown in ruvnet/ruflo.","triggerScenarios":"Thrown at v3/@claude-flow/cli/src/mcp-tools/security-tools.ts:75 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}