n8n-io/n8n · error · TypeORMError

To use streams you should install pg-query-stream package…

Error message

To use streams you should install pg-query-stream package. Please run npm i pg-query-stream --save command.

What it means

TypeORMError thrown from PostgresDriver.loadStreamDependency when require('pg-query-stream') throws, i.e. the optional pg-query-stream package is not installed. Streaming query APIs in the postgres driver depend on this optional peer dependency.

Solutions

  1. Install the package in the project that owns the running process: 'npm install pg-query-stream' (or add it to package.json dependencies).
  2. If you do not need streaming, switch to the non-streaming query API (e.g. find / query) to avoid the dependency entirely.
  3. Verify the install location is resolvable from the process working dir (not just from a workspace root the runtime cannot see).

Example fix

// before
// streaming call fails because pg-query-stream missing
// after
// run: npm install pg-query-stream
await repo.stream();
Defensive patterns

Strategy: validation

Validate before calling

// Probe for the optional dependency at startup, not on first use.
let hasPgQueryStream = false;
try {
  require.resolve('pg-query-stream');
  hasPgQueryStream = true;
} catch {}
if (!hasPgQueryStream && config.dbType === 'postgres') {
  // disable streaming endpoints or fail fast with a clear message
}

Try / catch

import { TypeORMError } from '@n8n/typeorm';
try {
  await repository.stream(cb);
} catch (e) {
  if (e instanceof TypeORMError && /pg-query-stream/.test(e.message)) {
    throw new Error('Streaming requires the pg-query-stream package; install it or use find().');
  }
  throw e;
}

Prevention

When it happens

Trigger: Caller invokes a streaming query method (e.g. repository.stream / driver.createQueryRunner streaming) which internally calls loadStreamDependency(), but pg-query-stream is not in node_modules.

Common situations: A deployment uses a custom image that pruned optional deps; a monorepo workspace hoisting dropped the package; the user followed an upstream TypeORM tutorial that assumes pg-query-stream is present.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/1c88e9f302e431eb. Report an issue: GitHub.

Appendix: source

Thrown at packages/@n8n/typeorm/src/driver/postgres/PostgresDriver.ts:1305

	 * Creates an escaped parameter.
	 */
	createParameter(parameterName: string, index: number): string {
		return this.parametersPrefix + (index + 1);
	}

	// -------------------------------------------------------------------------
	// Public Methods
	// -------------------------------------------------------------------------

	/**
	 * Loads postgres query stream package.
	 */
	loadStreamDependency() {
		try {
			return require('pg-query-stream');
		} catch (e) {
			// todo: better error for browser env
			throw new TypeORMError(
				`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

View on GitHub (pinned to 5ac6606e81)