Sara
Sara5mo ago

handling file type, and a small issue with a server package

Issue #1: I was trying to use the file system from google seen here -> google docs, in which I have a file called model.ts that already has some working structure (using async functions and convex built in functions), but when I try importing the GoogleAIFileManager I ran through this error:
Preparing Convex functions...
X [ERROR] Could not resolve "fs"

node_modules/.pnpm/@google+generative-ai@0.16.0/node_modules/@google/generative-ai/dist/server/index.mjs:1:29:
1 │ import { readFileSync } from 'fs';
~~~~

The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle
for node? You can use "platform: 'node'" to do that, which will remove this error.
Preparing Convex functions...
X [ERROR] Could not resolve "fs"

node_modules/.pnpm/@google+generative-ai@0.16.0/node_modules/@google/generative-ai/dist/server/index.mjs:1:29:
1 │ import { readFileSync } from 'fs';
~~~~

The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle
for node? You can use "platform: 'node'" to do that, which will remove this error.
and after further investigation, this could be the possible soultion -> some guy on github threads which I thought I'm already am? I know my code is complaing about the second line here:
const genAI = new GoogleGenerativeAI(apiKey as string);
const fileManager = new GoogleAIFileManager(apiKey as string)
const genAI = new GoogleGenerativeAI(apiKey as string);
const fileManager = new GoogleAIFileManager(apiKey as string)
so what would you suggest in this case? do I wrap it in an action and not use it in another file? Issue #2: I would like to pass my file as a file type to pass it through the google function that handles it for me without having to upload it somewhere or add to my cache history, and the code happend to complain that I used v.any() instead of defining it as a file like i did, what do I do in this case as a suggestion?
Error: File {} is not a supported Convex type (present at path .file in original object {"threadId":"m17a4k298pfydfecht4yevba7x6y1efy","content":"todododooleoeo","file":{}}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.
Error: File {} is not a supported Convex type (present at path .file in original object {"threadId":"m17a4k298pfydfecht4yevba7x6y1efy","content":"todododooleoeo","file":{}}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.
what should I do in this case?
GitHub
Googleapis return "Module not found: can't resolve fs" when running...
Thanks for stopping by to let us know something could be better! PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. ...
2 Replies
sshader
sshader5mo ago
Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error. usually means you want "use node" at the top of your Convex file that's using whichever node module it's complaining about (and also make sure there aren't any non "use node" files importing the "use node" ones). So yeah, "do I wrap it in an action and not use it in another file?" sounds about right. Re: the error about supported Convex types, all Convex functions must take in and return Convex Values (which are basically a subset of JSON). So you can't directly pass in a File object to a Convex function. I'm not familiar with this library, but I'd look into if there's some way to pass around some metadata (e.g. a file ID) that you could use to rehydrate the File object inside your Convex function
Sara
SaraOP5mo ago
so the "use node" part seemed to be working indeed! and I worked out the file type part too, so thanks!