n8n-io/n8n · critical · DriverPackageNotInstalledError
Postgres package has not been found installed. Try to instal
Error message
Postgres package has not been found installed. Try to install it: npm install pg --save
What it means
DriverPackageNotInstalledError('Postgres', 'pg') is thrown from PostgresDriver.loadDependencies when both this.options.driver is unset and require('pg') throws. The driver cannot operate without the pg client library; this fires during connect() before any real DB work.
Source
Thrown at packages/@n8n/typeorm/src/driver/postgres/PostgresDriver.ts:1324
`To use streams you should install pg-query-stream package. Please run npm i pg-query-stream --save command.`,
);
}
}
// -------------------------------------------------------------------------
// Protected Methods
// -------------------------------------------------------------------------
/**
* If driver dependency is not given explicitly, then try to load it via "require".
*/
protected loadDependencies(): void {
try {
const postgres = this.options.driver || require('pg');
this.postgres = postgres;
} catch (e) {
// todo: better error for browser env
throw new DriverPackageNotInstalledError('Postgres', 'pg');
}
}
/**
* Creates a new connection pool for a given database credentials.
*/
protected async createPool(
options: PostgresConnectionOptions,
credentials: PostgresConnectionCredentialsOptions,
): Promise<any> {
const { logger } = this.connection;
credentials = Object.assign({}, credentials);
// build connection options for the driver
// See: https://github.com/brianc/node-postgres/tree/master/packages/pg-pool#create
const connectionOptions: pg.PoolConfig = {
connectionString: credentials.url,
host: credentials.host,View on GitHub (pinned to 5ac6606e81)
Solutions
- Install pg in the package that runs the DataSource: 'npm install pg'.
- Pass the driver explicitly via options.driver = pg if installing globally is not possible (this short-circuits the require).
- For monorepos, ensure pg is a real dependency of the runtime workspace, not just of a sibling.
- Rebuild/reinstall node_modules if a prune step removed it.
Example fix
// before // DB_TYPE=postgres but pg not installed -> DriverPackageNotInstalledError // after npm install pg
Defensive patterns
Strategy: validation
Validate before calling
// At startup, probe that pg is resolvable when postgres is selected.
if (config.dbType === 'postgres') {
try { require.resolve('pg'); } catch {
throw new Error('pg package not installed; run npm install pg');
}
}
Try / catch
import { DriverPackageNotInstalledError } from '@n8n/typeorm';
try {
await dataSource.initialize();
} catch (e) {
if (e instanceof DriverPackageNotInstalledError && e.args?.[0] === 'Postgres') {
failStartup('Postgres driver needs the pg package; run npm install pg');
}
throw e;
}
Prevention
- Pin pg as a hard dependency in the package that runs the DataSource.
- Run a startup probe for the driver package matching DB_TYPE.
- In monorepos, ensure pg is hoisted to where the runtime resolves it.
- Audit image-pruning scripts so they do not strip pg.
When it happens
Trigger: DB_TYPE=postgres (or options.type='postgres') is configured but the 'pg' npm package is not installed in the running process; or pg is installed in a different workspace/node_modules than the one the process resolves from.
Common situations: Custom Docker image that did not include pg; pnpm hoisting / strict-node-loader setup that hides pg from the typeorm package; an upgrade that moved pg to optionalDependencies and it got pruned.
Related errors
- To use streams you should install pg-query-stream package. P
- SQLite package has not been found installed. Try to install
- Wrong driver: "${driverType}" given. Supported drivers are:
- Driver not Connected
- Database connection timed out
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/9a000656226df307.
Report an issue: GitHub.