{"record":{"id":"1c88e9f302e431eb","repo":"n8n-io/n8n","slug":"to-use-streams-you-should-install-pg-query-stream","errorCode":null,"errorMessage":"To use streams you should install pg-query-stream package. Please run npm i pg-query-stream --save command.","messagePattern":"To use streams you should install pg-query-stream package\\. Please run npm i pg-query-stream --save command\\.","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/driver/postgres/PostgresDriver.ts","lineNumber":1305,"sourceCode":"\t * Creates an escaped parameter.\n\t */\n\tcreateParameter(parameterName: string, index: number): string {\n\t\treturn this.parametersPrefix + (index + 1);\n\t}\n\n\t// -------------------------------------------------------------------------\n\t// Public Methods\n\t// -------------------------------------------------------------------------\n\n\t/**\n\t * Loads postgres query stream package.\n\t */\n\tloadStreamDependency() {\n\t\ttry {\n\t\t\treturn require('pg-query-stream');\n\t\t} catch (e) {\n\t\t\t// todo: better error for browser env\n\t\t\tthrow new TypeORMError(\n\t\t\t\t`To use streams you should install pg-query-stream package. Please run npm i pg-query-stream --save command.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// -------------------------------------------------------------------------\n\t// Protected Methods\n\t// -------------------------------------------------------------------------\n\n\t/**\n\t * If driver dependency is not given explicitly, then try to load it via \"require\".\n\t */\n\tprotected loadDependencies(): void {\n\t\ttry {\n\t\t\tconst postgres = this.options.driver || require('pg');\n\t\t\tthis.postgres = postgres;\n\t\t} catch (e) {\n\t\t\t// todo: better error for browser env","sourceCodeStart":1287,"sourceCodeEnd":1323,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/driver/postgres/PostgresDriver.ts#L1287-L1323","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install the package in the project that owns the running process: 'npm install pg-query-stream' (or add it to package.json dependencies).","If you do not need streaming, switch to the non-streaming query API (e.g. find / query) to avoid the dependency entirely.","Verify the install location is resolvable from the process working dir (not just from a workspace root the runtime cannot see)."],"exampleFix":"// before\n// streaming call fails because pg-query-stream missing\n// after\n// run: npm install pg-query-stream\nawait repo.stream();\n","handlingStrategy":"validation","validationCode":"// Probe for the optional dependency at startup, not on first use.\nlet hasPgQueryStream = false;\ntry {\n  require.resolve('pg-query-stream');\n  hasPgQueryStream = true;\n} catch {}\nif (!hasPgQueryStream && config.dbType === 'postgres') {\n  // disable streaming endpoints or fail fast with a clear message\n}\n","typeGuard":null,"tryCatchPattern":"import { TypeORMError } from '@n8n/typeorm';\ntry {\n  await repository.stream(cb);\n} catch (e) {\n  if (e instanceof TypeORMError && /pg-query-stream/.test(e.message)) {\n    throw new Error('Streaming requires the pg-query-stream package; install it or use find().');\n  }\n  throw e;\n}\n","preventionTips":["Declare pg-query-stream as a real dependency if you ship streaming features.","Probe for optional deps at startup and degrade gracefully.","Document which driver features require optional packages.","Avoid streaming APIs in code paths used by minimal deployments."],"tags":["typeorm","postgres","streams","dependencies","database"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}