CLI fails on Node.js < 18 with syntax error

Problem

Running npx postgresai@latest on Node.js versions below 18 fails with a syntax error:

file:///root/.npm/_npx/.../node_modules/postgresai/dist/bin/postgres-ai.js:794
      enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
                                                 ^
SyntaxError: Unexpected token '?'

This happens because:

  • The CLI declares engines.node >= 18 but npm/npx only warns, doesn't block
  • The nullish coalescing operator (??) requires Node 14+
  • ESM syntax requires Node 14+ for stable support

Solution

Lower the minimum Node.js requirement from 18 to 14:

  • Node 14+ supports ?? and ESM syntax that bun outputs
  • Add base64URLEncode helper for Node < 14.18 (native base64url was added in 14.18)

MR: !199 (closed)


Acceptance Criteria

  • The CLI minimum Node.js requirement is lowered from 18 to 14, or alternatively an explicit runtime version check displays a clear error message when running on unsupported Node.js versions (instead of a cryptic syntax error)
  • Users running npx postgresai@latest on Node.js 14-17 either get a working CLI or a clear "Node.js 18+ required" message
  • The base64URLEncode helper is added for Node.js versions below 14.18 (where native base64url support was added)
  • The ?? nullish coalescing operator works on all supported Node.js versions

Definition of Done

  • Fix merged (MR !199 (closed) or !201 (merged)) with appropriate Node.js version handling
  • Tested on Node.js 14, 16, 18, and 20 to confirm either correct operation or clear error message
  • No cryptic "SyntaxError: Unexpected token '?'" errors on any supported version
  • package.json engines field accurately reflects the actual minimum version
Edited by Nikolay Samokhvalov