google-gemini / generative-ai-js

The official Node.js / Typescript library for the Google Gemini API
https://ai.google.dev/
Apache License 2.0
502 stars 96 forks source link

Cannot find module '@google/generative-ai/files' or its corresponding type declarations. #155

Closed duccdev closed 1 month ago

duccdev commented 1 month ago

Description of the bug:

Hi everyone, I'm trying to import the GoogleAIFileManager class from @google/generative-ai/files However, VSCode and the TypeScript compiler itself throws errors about the module not existing I can import everything from @google/generative-ai but not @google/generative-ai/files

Actual vs expected behavior:

This should import the GoogleAIFileManager class:

import { GoogleAIFileManager } from "@google/generative-ai/files";

I get this error:

Cannot find module '@google/generative-ai/files' or its corresponding type declarations.

Any other information you'd like to share?

I peeked into the node_modules (specifically node_modules/@google/generative-ai/files/package.json) On this specific line:

  "name": "@google/generative-ai/files",

I get this warning from VSCode:

String does not match the pattern of "^(?:(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)?/[a-z0-9-._~])|[a-z0-9-~])[a-z0-9-._~]*$".

Could this be an issue when importing?

hsubox76 commented 1 month ago

Thanks for the report, I looked into it and it seems like the name format in node_modules/@google/generative-ai/files/package.json is incorrect, but not what's causing the issue. The issue is the paths further down in the file are wrong - should begin with../ and not ./. You can actually get around this by changing your tsconfig "module" field to "node16" or similar instead of "commonjs" (which makes it rely on the top-level package.json instead, which has the right paths) but I should be able to fix this quickly.

antoniovini47 commented 2 days ago

For those who are trying to do that recently and getting the same error. I found that Google made some changes and doesn't update some of the documentations.

You doesn't import anymore like:

import { GoogleAIFileManager } from "@google/generative-ai/files";

use

import { GoogleAIFileManager } from "@google/generative-ai/server";

instead.

Heres the only place they announced it:

image