Skip to content

pg-native after update [email protected] and [email protected]: Cannot read properties of null (reading 'Pool') #3431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cesco69 opened this issue Apr 23, 2025 · 4 comments

Comments

@cesco69
Copy link
Contributor

cesco69 commented Apr 23, 2025

{
    "name": "example",
    "version": "1.0.0",
    "main": "index.js",
    "dependencies": {
        "pg": "^8.15.1",
        "pg-native": "^3.4.0"
    },
    "sideEffects": false
}
const pg = require("pg");

const pool = new pg.native.Pool({ host: 'LOCALHOST' })
const result = await pool.query('SELECT 1');
console.log(result)

Error

2025-04-23 12:10:48 TypeError: Cannot read properties of null (reading 'Pool')
2025-04-23 12:10:48     at /opt/test/index.js:9:36
2025-04-23 12:10:48     at Layer.handleRequest (/opt/test/node_modules/router/lib/layer.js:152:17)
2025-04-23 12:10:48     at next (/opt/test/node_modules/router/lib/route.js:157:13)
2025-04-23 12:10:48     at Route.dispatch (/opt/test/node_modules/router/lib/route.js:117:3)
2025-04-23 12:10:48     at handle (/opt/test/node_modules/router/index.js:435:11)
2025-04-23 12:10:48     at Layer.handleRequest (/opt/test/node_modules/router/lib/layer.js:152:17)
2025-04-23 12:10:48     at /opt/test/node_modules/router/index.js:295:15
2025-04-23 12:10:48     at processParams (/opt/test/node_modules/router/index.js:582:12)
2025-04-23 12:10:48     at next (/opt/test/node_modules/router/index.js:291:5)
2025-04-23 12:10:48     at Function.handle (/opt/test/node_modules/router/index.js:186:3)
@cesco69 cesco69 changed the title pg-native stop working after update [email protected] and [email protected] pg-native after update [email protected] and [email protected]: Cannot read properties of null (reading 'Pool') Apr 23, 2025
@cesco69
Copy link
Contributor Author

cesco69 commented Apr 23, 2025

I have also tried

const Client = require("pg-native");
const client = new Client();
Error: Cannot find module './lib/build-result'
2025-04-23 12:20:14 Require stack:
2025-04-23 12:20:14 - /opt/test/node_modules/pg-native/index.js
2025-04-23 12:20:14 - /opt/test/index.js
2025-04-23 12:20:14     at Function._resolveFilename (node:internal/modules/cjs/loader:1405:15)
2025-04-23 12:20:14     at defaultResolveImpl (node:internal/modules/cjs/loader:1061:19)
2025-04-23 12:20:14     at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1066:22)
2025-04-23 12:20:14     at Function._load (node:internal/modules/cjs/loader:1215:37)
2025-04-23 12:20:14     at TracingChannel.traceSync (node:diagnostics_channel:322:14)
2025-04-23 12:20:14     at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
2025-04-23 12:20:14     at Module.require (node:internal/modules/cjs/loader:1491:12)
2025-04-23 12:20:14     at require (node:internal/modules/helpers:135:16)
2025-04-23 12:20:14     at Object.<anonymous> (/opt/test/node_modules/pg-native/index.js:6:19)
2025-04-23 12:20:14     at Module._compile (node:internal/modules/cjs/loader:1734:14) {
2025-04-23 12:20:14   code: 'MODULE_NOT_FOUND',
2025-04-23 12:20:14   requireStack: [ '/opt/test/node_modules/pg-native/index.js', '/opt/test/index.js' ]
2025-04-23 12:20:14 }

@brenoepics
Copy link
Contributor

This is likely a duplicate of #3429
the same fix (#3428) works for this issue too.

PoC code:

Image

Result with latest `pg`
Native: null
Native Pool: undefined
Result with the PR
Native: PG {
  defaults: {
    host: 'localhost',
    user: 'REDACTED',
    database: undefined,
    password: null,
    connectionString: undefined,
    port: 5432,
    rows: 0,
    binary: false,
    max: 10,
    idleTimeoutMillis: 30000,
    client_encoding: '',
    ssl: false,
    application_name: undefined,
    fallback_application_name: undefined,
    options: undefined,
    parseInputDatesAsUTC: false,
    statement_timeout: false,
    lock_timeout: false,
    idle_in_transaction_session_timeout: false,
    query_timeout: false,
    connect_timeout: 0,
    keepalives: 1,
    keepalives_idle: 0,
    parseInt8: [Setter]
  },
  Client: [Function (anonymous)] { Query: [Function (anonymous)] },
  Query: [Function (anonymous)],
  Pool: [class BoundPool extends Pool],
  _pools: [],
  Connection: [class Connection extends EventEmitter],
  types: {
    getTypeParser: [Function: getTypeParser],
    setTypeParser: [Function: setTypeParser],
    arrayParser: { create: [Function: create] },
    builtins: {
      BOOL: 16,
      BYTEA: 17,
      CHAR: 18,
      INT8: 20,
      INT2: 21,
      INT4: 23,
      REGPROC: 24,
      TEXT: 25,
      OID: 26,
      TID: 27,
      XID: 28,
      CID: 29,
      JSON: 114,
      XML: 142,
      PG_NODE_TREE: 194,
      SMGR: 210,
      PATH: 602,
      POLYGON: 604,
      CIDR: 650,
      FLOAT4: 700,
      FLOAT8: 701,
      ABSTIME: 702,
      RELTIME: 703,
      TINTERVAL: 704,
      CIRCLE: 718,
      MACADDR8: 774,
      MONEY: 790,
      MACADDR: 829,
      INET: 869,
      ACLITEM: 1033,
      BPCHAR: 1042,
      VARCHAR: 1043,
      DATE: 1082,
      TIME: 1083,
      TIMESTAMP: 1114,
      TIMESTAMPTZ: 1184,
      INTERVAL: 1186,
      TIMETZ: 1266,
      BIT: 1560,
      VARBIT: 1562,
      NUMERIC: 1700,
      REFCURSOR: 1790,
      REGPROCEDURE: 2202,
      REGOPER: 2203,
      REGOPERATOR: 2204,
      REGCLASS: 2205,
      REGTYPE: 2206,
      UUID: 2950,
      TXID_SNAPSHOT: 2970,
      PG_LSN: 3220,
      PG_NDISTINCT: 3361,
      PG_DEPENDENCIES: 3402,
      TSVECTOR: 3614,
      TSQUERY: 3615,
      GTSVECTOR: 3642,
      REGCONFIG: 3734,
      REGDICTIONARY: 3769,
      JSONB: 3802,
      REGNAMESPACE: 4089,
      REGROLE: 4096
    }
  },
  DatabaseError: [class DatabaseError extends Error],
  escapeIdentifier: [Function: escapeIdentifier],
  escapeLiteral: [Function: escapeLiteral],
  Result: [class Result],
  utils: {
    prepareValue: [Function: prepareValueWrapper],
    normalizeQueryConfig: [Function: normalizeQueryConfig],
    escapeIdentifier: [Function: escapeIdentifier],
    escapeLiteral: [Function: escapeLiteral]
  }
}
Native Pool: [class BoundPool extends Pool]

@brenoepics
Copy link
Contributor

pg-native also needs exports to ./lib/*, nice catch.

@brianc
Copy link
Owner

brianc commented Apr 23, 2025

this is fixed in the latest release. sorry for the headache!

@brianc brianc closed this as completed Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants