Reputation: 1
I am creating RAG application. My Tech-Stack is NextJS, Convex for storing users data and chat-history. Astra-DB for storing my vectorized data of documents. The problem is I want to connect my Astra-DB to my application under chat.ts which is under convex folder.
The problem is whenever I use node modules to create a connection, convex compiler gives node bundle error. I am attaching error below.
In tsconfig.json of convex I have excluded the node_modules. But still it is trying to bundle it:
{
/* This TypeScript project config describes the environment that
* Convex functions run in and is used to typecheck them.
* You can modify it, but some settings required to use Convex.
*/
"compilerOptions": {
/* These settings are not required by Convex and can be modified. */
"allowJs": true,
"strict": true,
/* These compiler options are required by Convex */
"target": "ESNext",
"lib": ["ES2021", "dom"],
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "./dist",
"rootDir": "./",
"esModuleInterop": true,
"isolatedModules": true,
"skipLibCheck": true,
"noEmit": true
},
"include": ["./**/*.ts"],
"exclude": ["./_generated", "../node_modules", "dist"]
}
Error:
In tsconfig.json of convex I have excluded the node_modules. But still it is trying to bundle it.
Upvotes: 0
Views: 303
Reputation: 6782
This is because you have a file in the convex folder that imports the package node-fetch
. In a convex action you can use fetch
directly, you don't need to import node-fetch; and node-fetch is a Node.js library, while Convex queries, mutations and actions don't run in Node.js.
If you need to use a Node.js library (for example, if an Astra-DB SDK required it) then you should create a new file in your convex folder that says
"use node";
import { action } from "./_generated/server";
export const yourAction = action((ctx, args) => {
...write your action here
});
where you'll be allowed to import Node.js libraries, because this file will be bundled differently and run in a Node.js environment.
Upvotes: 1