Skip to content

Commit 28d4268

Browse files
authored
fix(create-voltagent-app): align template module resolution with Node… (#587)
* fix(create-voltagent-app): align template module resolution with NodeNext * fix(create-voltagent-app): bundle template apps with tsdown * docs(quick-start): document tsdown bundling workflow
1 parent e089821 commit 28d4268

File tree

7 files changed

+78
-11
lines changed

7 files changed

+78
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-voltagent-app": patch
3+
---
4+
5+
Switch the app template to bundle with tsdown so the production build runs under Node ESM without manual .js extensions or bespoke import mappers.

packages/create-voltagent-app/src/utils/dependency-installer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const createBaseDependencyInstaller = async (
2828
type: "module",
2929
scripts: {
3030
dev: "tsx watch --env-file=.env ./src",
31-
build: "tsc",
31+
build: "tsdown",
3232
start: "node dist/index.js",
3333
lint: "biome check ./src",
3434
"lint:fix": "biome check --write ./src",
@@ -48,11 +48,12 @@ export const createBaseDependencyInstaller = async (
4848
devDependencies: {
4949
"@biomejs/biome": "^1.9.4",
5050
"@types/node": "^22.10.5",
51+
tsdown: "^0.15.2",
5152
tsx: "^4.19.2",
5253
typescript: "^5.7.3",
5354
},
5455
engines: {
55-
node: ">=20.0.0",
56+
node: ">=20.19.0",
5657
},
5758
};
5859

packages/create-voltagent-app/src/utils/templates.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export const getBaseTemplates = (): TemplateFile[] => {
1111
sourcePath: path.join(TEMPLATES_DIR, "base/tsconfig.json.template"),
1212
targetPath: "tsconfig.json",
1313
},
14+
{
15+
sourcePath: path.join(TEMPLATES_DIR, "base/tsdown.config.ts.template"),
16+
targetPath: "tsdown.config.ts",
17+
},
1418
{
1519
sourcePath: path.join(TEMPLATES_DIR, "base/README.md.template"),
1620
targetPath: "README.md",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Export all tools from this directory
2-
export { weatherTool } from "./weather";
2+
export { weatherTool } from "./weather";

packages/create-voltagent-app/templates/base/tsconfig.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
},
1212
"include": ["src"],
1313
"exclude": ["node_modules", "dist"]
14-
}
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from "tsdown";
2+
3+
export default defineConfig({
4+
entry: ["./src/index.ts"],
5+
sourcemap: true,
6+
outDir: "dist",
7+
});

website/docs/getting-started/quick-start.md

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import TabItem from '@theme/TabItem';
88

99
# Quick Start
1010

11-
There are two ways to create a VoltAgent application: Automatic setup or manual setup. While both work, the automatic setup provides the smoothest experience, especially for new users.
11+
There are two ways to create a VoltAgent application: Automatic setup or manual setup. While both work, the automatic setup provides the smoothest experience, especially for new users. Be sure your environment is running **Node.js 20.19 or newer** so the generated tsdown build works without ESM resolution issues.
1212

1313
### Automatic Setup (Recommended)
1414

@@ -72,10 +72,12 @@ The CLI will guide you through the setup process:
7272
7373
The tool will automatically:
7474
75-
- Create project files and structure
75+
- Create project files and structure (including a `tsdown.config.ts` build configuration)
7676
- Generate a `.env` file with your API key (if provided)
7777
- Initialize a git repository
78-
- Install dependencies Once the setup is complete, navigate to your project directory:
78+
- Install dependencies
79+
80+
Once the setup is complete, navigate to your project directory:
7981
8082
```bash
8183
cd my-voltagent-app
@@ -167,6 +169,39 @@ You should receive a response from your AI agent in the chat window. This confir
167169
168170
The `dev` script uses `tsx watch`, so it will automatically restart if you make changes to your code in the `src` directory. Press `Ctrl+C` in the terminal to stop the agent.
169171
172+
### Build for Production
173+
174+
When you're ready to deploy, bundle the app and run the compiled JavaScript with Node:
175+
176+
<Tabs>
177+
<TabItem value="npm" label="npm" default>
178+
179+
```bash
180+
npm run build
181+
npm start
182+
```
183+
184+
</TabItem>
185+
<TabItem value="yarn" label="yarn">
186+
187+
```bash
188+
yarn build
189+
yarn start
190+
```
191+
192+
</TabItem>
193+
<TabItem value="pnpm" label="pnpm">
194+
195+
```bash
196+
pnpm build
197+
pnpm start
198+
```
199+
200+
</TabItem>
201+
</Tabs>
202+
203+
The `build` script invokes **tsdown**, which bundles your TypeScript entrypoint (and any sibling directories such as `./workflows` or `./tools`) into `dist/index.js`. This extra step keeps the Node ESM loader from throwing `ERR_UNSUPPORTED_DIR_IMPORT` while preserving extensionless imports during development.
204+
170205
### Explore and Run Your Workflow from the Console
171206
172207
Your new project isn't just an agent; it's a powerful automation engine. We've included an expense approval workflow example to get you started, and you can run it directly from the VoltOps console.
@@ -256,14 +291,26 @@ Create a basic TypeScript configuration file (tsconfig.json):
256291
}
257292
```
258293
294+
Add a `tsdown.config.ts` alongside `tsconfig.json` so production builds bundle correctly:
295+
296+
```typescript
297+
import { defineConfig } from "tsdown";
298+
299+
export default defineConfig({
300+
entry: ["./src/index.ts"],
301+
sourcemap: true,
302+
outDir: "dist",
303+
});
304+
```
305+
259306
#### Install Dependencies
260307
261308
<Tabs>
262309
<TabItem value="npm" label="npm" default>
263310
264311
```bash
265312
# Install development dependencies
266-
npm install --save-dev typescript tsx @types/node @voltagent/cli
313+
npm install --save-dev typescript tsx tsdown @types/node @voltagent/cli
267314
268315
# Install dependencies
269316
npm install @voltagent/core @voltagent/libsql @voltagent/server-hono @voltagent/logger ai @ai-sdk/openai@^2 zod@3
@@ -274,7 +321,7 @@ npm install @voltagent/core @voltagent/libsql @voltagent/server-hono @voltagent/
274321
275322
```bash
276323
# Install development dependencies
277-
yarn add --dev typescript tsx @types/node @voltagent/cli
324+
yarn add --dev typescript tsx tsdown @types/node @voltagent/cli
278325
279326
# Install dependencies
280327
yarn add @voltagent/core @voltagent/libsql @voltagent/server-hono @voltagent/logger ai @ai-sdk/openai@^2 zod@3
@@ -285,7 +332,7 @@ yarn add @voltagent/core @voltagent/libsql @voltagent/server-hono @voltagent/log
285332
286333
```bash
287334
# Install development dependencies
288-
pnpm add --save-dev typescript tsx @types/node @voltagent/cli
335+
pnpm add --save-dev typescript tsx tsdown @types/node @voltagent/cli
289336
290337
# Install dependencies
291338
pnpm add @voltagent/core @voltagent/libsql @voltagent/server-hono @voltagent/logger ai @ai-sdk/openai@^2 zod@3
@@ -349,13 +396,15 @@ Add the following to your package.json:
349396
```json
350397
"type": "module",
351398
"scripts": {
352-
"build": "tsc",
399+
"build": "tsdown",
353400
"dev": "tsx watch --env-file=.env ./src",
354401
"start": "node dist/index.js",
355402
"volt": "volt" // Requires @voltagent/cli
356403
}
357404
```
358405
406+
`npm run build` (or `yarn build` / `pnpm build`) bundles your sources with tsdown before handing the output to Node via `npm start`.
407+
359408
Your project structure should now look like this:
360409
361410
```
@@ -365,6 +414,7 @@ my-voltagent-project/
365414
│ └── index.ts
366415
├── package.json
367416
├── tsconfig.json
417+
├── tsdown.config.ts
368418
├── .env
369419
└── .voltagent/ (created automatically when you run the agent)
370420
```

0 commit comments

Comments
 (0)