feat: migrate build system to ESM with tsdown
Summary
This PR introduces a comprehensive migration of the Motia monorepo build system from CommonJS to native ES Modules (ESM), replacing the previous build tooling (tsc/Vite) with tsdown across all packages. This modernization improves build performance, simplifies configuration, and ensures better compatibility with the modern JavaScript ecosystem.
Key Changes
-
ESM-first architecture: All packages now use
"type": "module"and output.mjsfiles - tsdown adoption: Replaced tsc/Vite build configurations with tsdown for consistent, fast builds
-
Updated TypeScript configuration: Changed module resolution to
bundlerand module format toESNext - Dependency updates: Updated TypeScript to 5.9.3, ts-jest to 29.4.5, and other dependencies
- Biome schema update: Updated to version 2.3.5
Related Issues
Type of Change
- [ ] Bug fix
- [x] New feature
- [ ] Breaking change
- [x] Refactor
- [ ] Other (please describe):
Packages Affected
Core Packages
-
@motiadev/core- Migrated to ESM with tsdown -
@motiadev/snap- Migrated to ESM with tsdown, updated CLI entry point
Adapter Packages
-
@motiadev/adapter-rabbitmq-events- Added tsdown config -
@motiadev/adapter-redis-cron- Added tsdown config -
@motiadev/adapter-redis-state- Added tsdown config -
@motiadev/adapter-redis-streams- Added tsdown config
Stream Client Packages
-
@motiadev/stream-client- Migrated to ESM with tsdown -
@motiadev/stream-client-browser- Added tsdown config -
@motiadev/stream-client-node- Migrated to ESM, removed custom build script -
@motiadev/stream-client-react- Added tsdown config
UI Packages
-
@motiadev/ui- Replaced Vite with tsdown -
@motiadev/workbench- Migrated to tsdown, updated post-build script
Plugins
-
plugin-endpoint- Replaced Vite with tsdown -
plugin-example- Replaced Vite with tsdown -
plugin-logs- Replaced Vite with tsdown -
plugin-observability- Replaced Vite with tsdown -
plugin-states- Replaced Vite with tsdown
Changes Overview
Build System Changes
| Before | After |
|---|---|
tsc for TypeScript compilation |
tsdown for bundling |
| Vite for plugin builds | tsdown for all builds |
CommonJS (require) |
ESM (import) |
.js output files |
.mjs output files |
dist/cjs/ and dist/esm/ |
dist/ (ESM only) |
Package.json Export Changes
// Before
{
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts"
}
// After
{
"type": "module",
"main": "dist/index.mjs",
"module": "dist/index.mjs",
"types": "dist/index.d.mts"
}
Test Configuration
- Jest now runs with
NODE_OPTIONS='--experimental-vm-modules'for ESM support - Migrated
jest.config.jstojest.config.cjswhere needed
Checklist
- [x] I have read the CONTRIBUTING.md
- [x] My code follows the code style of this project
- [x] I have added tests where applicable
- [x] I have tested my changes locally
- [ ] I have linked relevant issues
- [ ] I have added screenshots for UI changes (if applicable)
Testing Performed
- [ ] All packages build successfully with
pnpm build - [ ] Unit tests pass with ESM configuration
- [ ] Playground runs correctly with updated packages
- [ ] Workbench starts and functions properly
- [ ] CLI commands work as expected
Migration Notes
For Contributors
- Use
importsyntax instead ofrequire - File extensions may be needed in imports for certain edge cases
- Jest tests now require
--experimental-vm-modulesflag
For Users
- No breaking changes in public API
- Import paths remain the same
- TypeScript users get improved module resolution
Additional Context
This migration prepares Motia for better tree-shaking, faster builds, and improved compatibility with modern tooling. The tsdown bundler was chosen for its simplicity, speed, and excellent TypeScript support.
Files Added
-
tsdown.config.tsin each package (17 new configs) -
jest.config.cjsfor packages needing CommonJS Jest config
Files Removed
-
vite.config.tsfrom plugins and UI packages -
scripts/build.shfrom several packages -
tsconfig.build.jsonandtsconfig.node.jsonwhere redundant - Various
.d.tsdeclaration files that are now auto-generated
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| motia-docs | Preview | Comment | Dec 2, 2025 6:52pm | |
| motia-ui | Preview | Comment | Dec 2, 2025 6:52pm |
⚠️ This PR is quite large (>1000 lines). Consider splitting it into smaller PRs for easier review.
Dependency Review
The following issues were found:
- ✅ 0 vulnerable package(s)
- ✅ 0 package(s) with incompatible licenses
- ✅ 0 package(s) with invalid SPDX license definitions
- ⚠️ 18 package(s) with unknown licenses.
- ⚠️ 8 packages with OpenSSF Scorecard issues.
E2E Test Results ✅
All tests have completed. Tests passed.
Matrix: 2 OS (Ubuntu, macOS) × 2 Templates (TypeScript, Python) = 4 jobs
This comment is automatically posted by the PR E2E Results workflow.