#another copy of javascript when adding tsconfig.json
3 messages · Page 1 of 1 (latest)
Let me check the knowledge base for you. One moment! :books:
Convex uses code generation to create code that is specific to your app's data model and API. When you run npx convex dev, it generates JavaScript files (.js) with TypeScript type definitions (.d.ts) in a convex/_generated directory. This is why you're seeing a JavaScript file for every TypeScript file in your project.
The generated code isn't required to use Convex, but it provides better autocompletion in your editor and more type safety if you're using TypeScript.
Here's the command to generate the code:
npx convex dev
This command creates a convex/_generated directory that contains api.js and api.d.ts, dataModel.d.ts, server.js and server.d.ts.
If you're seeing errors or unexpected behavior, make sure your tsconfig.json file is correctly configured. For example, you might need to add allowJs: true to your project-level tsconfig.json file.
For more information, you can refer to the Convex documentation (https://docs.convex.dev/generated-api) and the TypeScript documentation (https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
Sources:
- Generated Code (https://docs.convex.dev/generated-api)
- Discord support thread: Compiling Node.js script that uses convex _generated/api.js (https://discord.com/channels/1019350475847499849/1215791200980963379)
- Discord support thread: convex not compiling due to TS/Flow errors (https://discord.com/channels/1019350475847499849/1211940193989296138)