Search code examples
node.jstypescriptgoogle-cloud-platformgoogle-gemini

Cannot find module '@google/generative-ai/files' with Type Declaration File Present (ts(2307))


I'm encountering an error in my Node.js (typescript) project related to the @google/generative-ai package. Here's the specific message:

"Cannot find module '@google/generative-ai/files' or its corresponding type declarations.ts(2307)"

However, I've verified that the type declaration file exists in my node_modules directory.

What I've tried:

  • Checked tsconfig.json configuration for moduleResolution and path settings.
  • Reinstalled the @google/generative-ai package.
  • Cleared yarn cache.
  • Restarted VS Code.
  • A friend of mine tried the same, same error on his hand.

package.json:

{
  "name": "basic",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
    "engines": {
    "node": "20"
  },
  "dependencies": {
    "@google/generative-ai": "^0.11.3",
    "@types/react": "^18.3.2",
    "common-tags": "^1.8.2"
  },
  "scripts": {
    "dev": "node -r ts-node/register --env-file=.env src/index.ts"
  },
  "devDependencies": {
    "@types/common-tags": "^1.8.4",
    "@types/node": "^20.12.7",
    "ts-node": "^10.9.2",
    "typescript": "^5.4.5"
  }
}

Has anyone else faced this specific issue with the @google/generative-ai package, even though the type declaration file is present? Any suggestions on how to solve this?


Solution

  • Solved by installing the latest version of the package. Try yarn add @google/generative-ai@latest if this ever happens to you.