genkit icon indicating copy to clipboard operation
genkit copied to clipboard

[JS] Cannot find module 'pg-protocol/dist/messages' or its corresponding type declarations.

Open 10eputzen opened this issue 8 months ago • 6 comments

When building my cloud function for production I get this error message:

node_modules/@opentelemetry/instrumentation-pg/node_modules/@types/pg/index.d.ts:12:31 - error TS2307: Cannot find module 'pg-protocol/dist/messages' or its corresponding type declarations.

12 import { NoticeMessage } from 'pg-protocol/dist/messages';
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error in node_modules/@opentelemetry/instrumentation-pg/node_modules/@types/pg/index.d.ts:12

It worked fine in my firebase emulators and this is how I imported it into my cloud function (v2)

import { enableFirebaseTelemetry } from '@genkit-ai/firebase'
enableFirebaseTelemetry()

To Reproduce Steps to reproduce the behavior:

  1. add enableFirebaseTelemetry to a cloud function v2
  2. npm run build Expected behavior build runs

Desktop (please complete the following information):

  • OS: Windows with WSL2
  • Version "@genkit-ai/googleai": "^1.8.0",

Additional context Here is my package.json:

{
  "name": "functions",
  "scripts": {
    "build": "tsc",
    "build:watch": "tsc --watch",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "22"
  },
  "main": "lib/index.js",
  "dependencies": {
    "@genkit-ai/firebase": "^1.8.0",
    "@genkit-ai/googleai": "^1.8.0",
    "@opentelemetry/api": "^1.9.0",
    "axios": "^1.7.3",
    "cors": "^2.8.5",
    "firebase-admin": "^13.0.2",
    "firebase-functions": "^6.3.2",
    "genkit": "^1.8.0",
    "html-to-text": "^9.0.5",
    "nodemailer": "^6.10.1",
    "sanitize-html": "^2.11.0"
  },
  "devDependencies": {
    "@types/cors": "^2.8.17",
    "@types/html-to-text": "^9.0.4",
    "@types/nodemailer": "^6.4.17",
    "@types/sanitize-html": "^2.15.0",
    "@typescript-eslint/eslint-plugin": "^8.28.0",
    "@typescript-eslint/parser": "^8.28.0",
    "eslint": "^9.23.0",
    "firebase-functions-test": "^3.1.0",
    "typescript": "^5.5.3"
  },
  "private": true
}

10eputzen avatar May 13 '25 16:05 10eputzen

Same issue here.

Not a solution but a hacky workaround:

Skip library check in functions/tsconfig.json:

{
  "compilerOptions": {
    "skipLibCheck": true,
    ...
  }
}

Soolan avatar May 14 '25 10:05 Soolan

Same here.

egorFiNE avatar May 16 '25 14:05 egorFiNE

same here

ashwanikmar avatar May 16 '25 15:05 ashwanikmar

See https://github.com/brianc/node-postgres/issues/3457

mvarendorff avatar May 31 '25 16:05 mvarendorff

the latest version of @types/pg (8.15.1) had already resolved the issue, so I installed the latest version and it worked.

See https://github.com/brianc/node-postgres/issues/3457#issuecomment-2865098355 What I do: npm install --save-dev @types/pg

gomano-shigure avatar Jun 02 '25 09:06 gomano-shigure

the latest version of @types/pg (8.15.1) had already resolved the issue, so I installed the latest version and it worked.

See brianc/node-postgres#3457 (comment) What I do: npm install --save-dev @types/pg

not for me

10eputzen avatar Jun 02 '25 10:06 10eputzen

Running into the same thing. Installing the latest @types/pg did not help. Did anyone else find non hacky fix?

adamkoch avatar Jun 20 '25 02:06 adamkoch

To answer my own question, this fixes it for now till genkit is updated to latest dep:

  "overrides": {
    "@types/pg": "8.15.4"
  },

adamkoch avatar Jun 20 '25 03:06 adamkoch