Lord Dorkus
Lord Dorkus2y ago

dotenv import error

Does anyone know where I should add this recommended "platform: 'node'" piece of code it's suggesting? I'm trying to set-up convex to a front-end web project I already have going. Any advice would be greatly appreciated.
No description
9 Replies
ballingt
ballingt2y ago
It looks like you're importing/requiring the dotenv library from a convex function, which isn't supported and shouldn't be necessary Is there a file in the convex folder importing dotenv? Ir maybe it's an indirect dependency, what libraries are you using from files in the convex folder?
Lord Dorkus
Lord DorkusOP2y ago
Let me have a look
Presley
Presley2y ago
Seems you functions depend on Node.js, which is not supported in queries and mutations. You can use npm libraries that depend on Node.js in actions by adding “use node”; declaration to the top of the file. See https://docs.convex.dev/functions/actions for more details.
Actions | Convex Developer Hub
Actions can call third party services to do things such as processing a payment
Lord Dorkus
Lord DorkusOP2y ago
That makes sense! Let me try that. Would I only use the "use node"; in the convex folder? The error seems to be coming from generated package-lock.json and package.json files.
ian
ian2y ago
To expand on dotenv in particular, dotenv is used to load environment variables. For convex function, you define those environment variables in the dashboard. You’d need to separate your query and mutation function into separate files from your actions, and only in your actions would you put “use node”; And yes query mutation and action are all defined in the convex/ folder. You may also have code that is importing from a file that uses dotenv. In general your server functions shouldn’t import from browser code and visa versa. To share code you’d want to make a file that they both import from, which doesn’t import client-specific or server-specific libraries
Lord Dorkus
Lord DorkusOP2y ago
Alright. I was following the directions here: https://docs.convex.dev/quickstart/nodejs. When I follow those, I think it creates the dotenv file.
ian
ian2y ago
Yes the .env and .env.local are for variables that get loaded in the browser code (outside of the convex folder) Or node code that’s outside convex Are you trying to build a website or interact with Convex through a nodejs client? I think the react or next JS quickstarts are probably a better starting point for a website.
Lord Dorkus
Lord DorkusOP2y ago
That's what I'm trying to do. I'll look into React and JS quickstart. Those seem like they might be easier for what I'm trying to do. Thanks for all your help!
ian
ian2y ago
No sweat! The tutorial is the best spot to start, if you’re looking to learn about convex. QuickStarts are good for starting a project from scratch. Best of luck!

Did you find this page helpful?