{"record":{"id":"d32c222d24fc315f","repo":"ruvnet/ruflo","slug":"pg-node-postgres-package-not-found-install-it-w","errorCode":null,"errorMessage":"pg (node-postgres) package not found. Install it with: npm install pg","messagePattern":"pg \\(node-postgres\\) package not found\\. Install it with: npm install pg","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/plugins/src/integrations/ruvector/ruvector-bridge.ts","lineNumber":259,"sourceCode":"      };\n\n      return connectionResult;\n    } catch (error) {\n      this.isConnected = false;\n      throw new Error(`Failed to initialize connection pool: ${(error as Error).message}`);\n    }\n  }\n\n  /**\n   * Load pg module dynamically.\n   */\n  private async loadPg(): Promise<PoolFactory> {\n    try {\n      // Try to import pg\n      const pg: any = await import('pg');\n      return pg.default ?? pg;\n    } catch {\n      throw new Error(\n        'pg (node-postgres) package not found. Install it with: npm install pg'\n      );\n    }\n  }\n\n  /**\n   * Build pool configuration from RuVector config.\n   */\n  private buildPoolConfig(): PgPoolConfig {\n    const poolSettings = (this.config.pool ?? {}) as Partial<PoolConfig>;\n\n    return {\n      host: this.config.host,\n      port: this.config.port,\n      database: this.config.database,\n      user: this.config.user,\n      password: this.config.password,\n      ssl: this.config.ssl","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/plugins/src/integrations/ruvector/ruvector-bridge.ts#L241-L277","documentation":"Thrown by loadPg() when the dynamic import('pg') fails. The bridge deliberately treats node-postgres as an optional dependency and imports it lazily to avoid bundling issues; if the package is absent from the runtime's node_modules (or unreachable from the bundle), the import rejects and this actionable error replaces the raw module-not-found.","triggerScenarios":"Running the bridge in a project that never installed pg; a bundler (webpack/esbuild) that resolved but then excluded the dynamic import; pnpm strict node_modules hoisting where pg is not a declared dependency of the consuming package.","commonSituations":"Optional peer dependency not installed after adding the integration; Docker image built from a pruned dependency tree; monorepo where pg is installed only in a sibling package.","solutions":["Install the driver in the runtime package: npm install pg (plus npm install -D @types/pg for TypeScript)","After installing, verify the runtime can resolve it: node -e \"import('pg').then(() => console.log('ok'))\"","For bundlers, mark pg as external so the dynamic import stays a runtime require","In pnpm monorepos, declare pg in the consuming package's dependencies, not just a sibling's"],"exampleFix":"# before\nnpm run start # throws: pg (node-postgres) package not found\n\n# after\nnpm install pg && npm install -D @types/pg\nnpm run start","handlingStrategy":"validation","validationCode":"// probe for the driver before touching the bridge\nimport { createRequire } from 'node:module';\nconst require_ = createRequire(import.meta.url);\nlet pgAvailable = false;\ntry {\n  require_.resolve('pg');\n  pgAvailable = true;\n} catch {\n  pgAvailable = false;\n}\nif (!pgAvailable) {\n  throw new Error('pg is not installed — run: npm install pg');\n}\nawait bridge.initialize();","typeGuard":null,"tryCatchPattern":"try {\n  await bridge.initialize();\n} catch (err) {\n  if ((err as Error).message.includes('pg (node-postgres) package not found')) {\n    throw new Error('Dependency missing at runtime: npm install pg');\n  }\n  throw err;\n}","preventionTips":["Declare pg (and @types/pg) as a real dependency of the deploying package, not a transitive hope","Mark pg external when bundling so the lazy import resolves at runtime","Smoke-test the production image with node -e \"import('pg').then(()=>console.log('ok'))\""],"tags":["database","postgres","missing-dependency","npm","dynamic-import"],"backgroundTag":"missing-dependency","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}