Back to Creative & Visual

Motion Canvas Setup and Integration

animationtypescriptvitevideocanvas
⭐ 28.1kπŸ“„ MITπŸ•’ 2026-06-16Source β†—

Install this skill

npx skills add davila7/claude-code-templates

Works across Claude Code, Cursor, Codex, Copilot & Antigravity

Motion Canvas allows developers to build programmatic, high-performance animations using TypeScript. Instead of traditional video editing software, you define movement through generator functions, signals, and the Canvas API. This skill set is essential for creators who need to sync visual diagrams, text animations, or UI transitions with audio or code-based logic. It provides a standardized project structure that handles the tricky interoperability between CommonJS-based plugins and modern ESM environments, which often cause build failures in fresh Vite setups. Whether you are generating educational content, technical explainers, or data visualizations, this approach ensures your animation project remains maintainable and type-safe. By separating the scene logic from the build configuration, you gain a repeatable workflow for generating frame-perfect assets directly from your codebase.
By davila7

What this skill does

  • β€’Programmatic animation authoring with generator functions
  • β€’Reactive state management using signals
  • β€’ESM/CommonJS configuration bridge for Vite
  • β€’TypeScript-first rendering pipeline
  • β€’Real-time animation previewing

When to use it

  • βœ“Creating technical explainers or video documentation
  • βœ“Automating consistent UI animation sequences
  • βœ“Generating complex data-driven visual graphs
  • βœ“Syncing code demonstrations with narration audio

When not to use it

  • βœ•Direct video editing or post-production compositing
  • βœ•High-fidelity raster-based movie editing
  • βœ•Simple web-based UI interactions that don't require video output

How to invoke it

Example prompts that trigger this skill:

  • β€œSet up a new Motion Canvas project structure.”
  • β€œHelp me configure vite.config.js for Motion Canvas.”
  • β€œFix my ESM import errors for @motion-canvas/vite-plugin.”
  • β€œGuide me through creating a scene in Motion Canvas.”
  • β€œWhat dependencies do I need for a Motion Canvas build?”

Example workflow

  1. Initialize a new directory and run npm init -y.
  2. Add type: module to package.json for ESM support.
  3. Install @motion-canvas packages including the core, ui, and plugin.
  4. Configure vite.config.js using the createRequire workaround.
  5. Write an animation scene in src/scenes/ using generator functions.
  6. Start the development server to view the real-time animation preview.

Prerequisites

  • –Node.js
  • –npm or yarn
  • –Basic TypeScript knowledge

Pitfalls & limitations

  • !Standard ES module imports fail for the vite plugin.
  • !Requires manual 'createRequire' handling to bridge CJS/ESM.
  • !Vite config must remain a .js file to ensure correct build order.

FAQ

Why does my Motion Canvas build fail with import errors?
The @motion-canvas/vite-plugin is CommonJS. You must use the createRequire() workaround in a .js vite configuration file instead of standard ESM imports.
Do I need to write my config in TypeScript?
No, using a .js file for vite.config is recommended to avoid complex type resolution issues during the initial build phase.
Is Motion Canvas suitable for live web UI?
It is intended for programmatic video production. While it uses Canvas, its architecture is specialized for rendering frames to video, not real-time browser interaction.

How it compares

Doing this manually requires debugging complex Vite/CJS resolution issues; this skill automates the exact configuration needed to bypass those specific build blockers.

Source & trust

⭐ 28k starsπŸ“„ MITπŸ•’ Updated 2026-06-16πŸ›‘ runs-shell, network

From the source: β€œ# Motion Canvas - Production-Ready Video Creation with TypeScript Complete production-ready skill for creating programmatic videos using Motion Canvas, including critical ESM/CommonJS workarounds, full configuration templates, and comprehensive troubleshooting. ## ⚠️ CRITICAL: ESM/CommonJS Interoper…”

View the full SKILL.md source

# Motion Canvas - Production-Ready Video Creation with TypeScript

Complete production-ready skill for creating programmatic videos using Motion Canvas, including critical ESM/CommonJS workarounds, full configuration templates, and comprehensive troubleshooting.

## ⚠️ CRITICAL: ESM/CommonJS Interoperability Issue

**IMPORTANT**: The `@motion-canvas/vite-plugin` package is distributed as CommonJS, which causes import errors in modern ESM projects. The standard `import motionCanvas from '@motion-canvas/vite-plugin'` **WILL NOT WORK**.

You MUST use the `createRequire` workaround documented in the Setup section below.

## When to use

Use this skill whenever you are dealing with Motion Canvas code to obtain domain-specific knowledge about:

- Creating animated videos using TypeScript and generator functions
- Building animations with signals and reactive values
- Working with vector graphics and Canvas API
- Synchronizing animations with voice-overs and audio
- Using the real-time preview editor for instant feedback
- Implementing procedural animations with flow control
- Creating informative visualizations and diagrams
- Animating text, shapes, and custom components
- **Setting up Motion Canvas projects from scratch with correct configuration**
- **Troubleshooting common setup and build errors**

## Core Concepts

Motion Canvas allows you to create videos using:
- **Generator Functions**: Describe animations using JavaScript generators with `yield*` syntax
- **Signals**: Reactive values that automatically update dependent properties
- **Real-time Preview**: Live editor with instant preview powered by Vite
- **TypeScript-First**: Write animations in TypeScript with full IDE support
- **Canvas API**: Leverage 2D Canvas for high-performance vector rendering
- **Audio Synchronization**: Sync animations precisely with voice-overs

## Complete Setup Guide

### Step 1: Initialize Project

```bash
# Create project directory
mkdir my-motion-canvas-project
cd my-motion-canvas-project

# Initialize package.json
npm init -y
```

### Step 2: Configure package.json for ESM

**CRITICAL**: Add `"type": "module"` to enable ESM imports.

```json
{
  "name": "my-motion-canvas-project",
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  }
}
```

### Step 3: Install ALL Required Dependencies

**CRITICAL**: Must include `@motion-canvas/ui` - the plugin will fail without it.

```bash
npm install --save-dev @motion-canvas/core @motion-canvas/2d @motion-canvas/vite-plugin @motion-canvas/ui vite typescript
```

### Step 4: Create Project Structure

```
my-motion-canvas-project/
β”œβ”€β”€ package.json          # "type": "module" required
β”œβ”€β”€ vite.config.js        # Use .js NOT .ts (see Step 5)
β”œβ”€β”€ tsconfig.json         # TypeScript configuration
β”œβ”€β”€ index.html            # HTML entry point
└── src/
    β”œβ”€β”€ project.ts        # Project configuration with scenes
    └── scenes/
        └── example.tsx   # Animation scene
```

### Step 5: Create vite.config.js with ESM/CommonJS Workaround

**CRITICAL**: Use `vite.config.js` (NOT `.ts`) with the `createRequire` workaround.

**File: `vite.config.js`**
```javascript
import {defineConfig} from 'vite';
import {createRequire} from 'module';

// WORKAROUND: @motion-canvas/vite-plugin is CommonJS, must use require
const require = createRequire(import.meta.url);
const motionCanvasModule = require('@motion-canvas/vite-plugin');
const motionCanvas = motionCanvasModule.default || motionCanvasModule;

export default defineConfig({
  plugins: [
    motionCanvas({
      project: './src/project.ts',
    }),
  ],
});
```

**Why .js instead of .ts?**
- Vite config runs before TypeScript compilation
- The `createRequire` workaround works reliably in plain JavaScript
- Avoids additional type resolution complexity

### Step 6: Create tsconfig.json

**CRITICAL**: Include `esModuleInterop` and `allowSyntheticDefaultImports`.

**File: `tsconfig.json`**
```json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ES2020",
    "lib": ["ES2020", "DOM"],
    "jsx": "react-jsx",
    "jsxImportSource": "@motion-canvas/2d/lib",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}
```

### Step 7: Create index.html

**File: `index.html`**
```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Motion Canvas Project</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/project.ts"></script>
</body>
</html>
```

### Step 8: Create src/project.ts

**File: `src/project.ts`**
```typescript
import {makeProject} from '@motion-canvas/core';
import example from './scenes/example?scene';

export default makeProject({
  scenes: [example],
});
```

### Step 9: Create First Animation Scene

**File: `src/scenes/example.tsx`**
```typescript
import {makeScene2D} from '@motion-canvas/2d/lib/scenes';
import {Circle} from '@motion-canvas/2d/lib/components';
import {createRef} from '@motion-canvas/core/lib/utils';
import {all} from '@motion-canvas/core/lib/flow';

export default makeScene2D(function* (view) {
  const circleRef = createRef<Circle>();

  view.add(
    <Circle
      ref={circleRef}
      size={70}
      fill="#e13238"
    />,
  );

  // Animate circle size and position
  yield* circleRef().size(140, 1);
  yield* circleRef().position.x(300, 1);
  yield* circleRef().fill('#e6a700', 1);

  // Parallel animations
  yield* all(
    circleRef().scale(1.5, 0.5),
    circleRef().rotation(360, 1)
  );
});
```

### Step 10: Run Development Server

```bash
npm run dev
```

Open browser at `http://localhost:5173` to see the Motion Canvas editor.

## Troubleshooting

### Error: `TypeError: motionCanvas is not a function`

**Cause**: ESM/CommonJS interoperability issue with `@motion-canvas/vite-plugin`

**Solution**: Use the `createRequire` workaround in `vite.config.js` (see Step 5)

```javascript
// ❌ WRONG - Will not work
import motionCanvas from '@motion-canvas/vite-plugin';

// βœ… CORRECT - Use createRequire
import {createRequire} from 'module';
const require = createRequire(import.meta.url);
const motionCanvasModule = require('@motion-canvas/vite-plugin');
const motionCanvas = motionCanvasModule.default || motionCanvasModule;
```

### Error: `Cannot find module '@motion-canvas/ui'`

**Cause**: Missing required dependency

**Solution**: Install the UI package:
```bash
npm install --save-dev @motion-canvas/ui
```

### Error: `Property 'default' does not exist on type ...`

**Cause**: TypeScript configuration missing ESM interop settings

**Solution**: Add to `tsconfig.json`:
```json
{
  "compilerOptions": {
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  }
}
```

### Warning: `The CJS build of Vite's Node API is deprecated`

**Status**: This is a known warning and can be safely ignored. It appears because `@motion-canvas/vite-plugin` is CommonJS. The workaround ensures functionality despite the warning.

### Error: `Failed to resolve import "*.tsx?scene"`

**Cause**: Vite plugin not properly loaded or configured

**Solution**:
1. Verify `vite.config.js` has the correct workaround
2. Check `project` path points to correct file: `'./src/project.ts'`
3. Ensure scene imports use `?scene` suffix: `import example from './scenes/example?scene';`

### Build fails with TypeScript errors

**Solution**:
1. Verify `tsconfig.json` includes all required options (see Step 6)
2. Check `jsxImportSource` is set to `@motion-canvas/2d/lib`
3. Ensure all dependencies are installed

## How to use

Read individual rule files for detailed explanations and code examples:

### Core Animation Concepts
- **[references/generators.md](references/generators.md)** - Generator functions for describing animations
- **[references/signals.md](references/signals.md)** - Reactive signals for dynamic properties and dependencies
- **[references/animations.md](references/animations.md)** - Tweening properties and creating smooth animations

For additional topics like scenes, shapes, text rendering, audio synchronization, and advanced features, refer to the comprehensive [Motion Canvas official documentation](https://motioncanvas.io/docs).

## Complete Working Example

This is a complete, tested project structure that works out of the box:

```
my-motion-canvas-project/
β”œβ”€β”€ package.json
β”‚   {
β”‚     "name": "my-motion-canvas-project",
β”‚     "type": "module",
β”‚     "scripts": {
β”‚       "dev": "vite",
β”‚       "build": "vite build"
β”‚     },
β”‚     "devDependencies": {
β”‚       "@motion-canvas/core": "^3.0.0",
β”‚       "@motion-canvas/2d": "^3.0.0",
β”‚       "@motion-canvas/vite-plugin": "^3.0.0",
β”‚       "@motion-canvas/ui": "^3.0.0",
β”‚       "vite": "^5.0.0",
β”‚       "typescript": "^5.0.0"
β”‚     }
β”‚   }
β”‚
β”œβ”€β”€ vite.config.js (with createRequire workaround)
β”œβ”€β”€ tsconfig.json (with esModuleInterop)
β”œβ”€β”€ index.html
└── src/
    β”œβ”€β”€ project.ts (makeProject with scenes array)
    └── scenes/
        └── example.tsx (makeScene2D with animations)
```

## Best Practices

1. **Always use the createRequire workaround** - Don't try standard ESM imports for the Vite plugin
2. **Use vite.config.js not .ts** - Avoids additional compilation complexity
3. **Include all dependencies** - Don't forget `@motion-canvas/ui`
4. **Use generator functions** - All scene animations should use `function*` and `yield*` syntax
5. **Leverage signals** - Create reactive dependencies between properties
6. **Think in durations** - Specify animation duration in seconds as the second parameter
7. **Use refs for control** - Create references to nodes for precise animation control
8. **Preview frequently** - Take advantage of the real-time editor for instant feedback
9. **Organize scenes** - Break complex animations into multiple scenes
10. **Type everything** - Use TypeScript for better IDE support and fewer errors

## Common Pitfalls to Avoid

1. ❌ Forgetting `"type": "module"` in package.json
2. ❌ Using standard import for `@motion-canvas/vite-plugin`
3. ❌ Not installing `@motion-canvas/ui`
4. ❌ Missing `esModuleInterop` in tsconfig.json
5. ❌ Using `vite.config.ts` instead of `vite.config.js`
6. ❌ Forgetting `?scene` suffix in scene imports

## Resources

- **Documentation**: https://motioncanvas.io/docs
- **Repository**: https://github.com/motion-canvas/motion-canvas
- **Examples**: https://motioncanvas.io/docs/quickstart
- **Community**: Discord and GitHub Discussions
- **License**: MIT

Quoted from davila7/claude-code-templates for reference β€” see the original for the authoritative, latest version.

How to Use This Skill Unit

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/skills/motion-canvas/
  3. Save the file as SKILL.md
  4. The agent will automatically discover the skill based on its description.

Option B: Global Installation (All Agents)

Save the file to these locations to make it available across all projects:

  • Claude Code: ~/.claude/skills/davila7/claude-code-templates/motion-canvas/SKILL.md
  • Cursor: ~/.cursor/skills/davila7/claude-code-templates/motion-canvas/SKILL.md
  • Antigravity: ~/.gemini/antigravity/skills/davila7/claude-code-templates/motion-canvas/SKILL.md

πŸš€ Install with CLI:
npx skills add davila7/claude-code-templates

Read the Master Guide: Mastering Agent Skills β†’

Recommended Rules

View more rules β†’

Recommended Workflows

View more workflows β†’

Recommended MCP Servers

View more MCP servers β†’

Take It Further

Maximize your productivity with these powerful resources

πŸ“‹

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
πŸ“–

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide

How to use this Skill in Claude Code & Cursor

For Claude Code (CLI)

To use this skill in Claude Code, copy the rule content into your project's custom instructions or follow our Add-Skill CLI guide. This ensures Claude follows your standards during every code generation.

For Cursor & Windsurf

For Cursor or Windsurf, individual skills are best used in the "Rules for AI" section. This specific unit helps the agent avoid creative & visual issues, leading to cleaner, more efficient code.

Why the skill format matters: the standardized Agent Skills format lets your AI agent load detailed instructions only when they are relevant, keeping your prompt clean while improving results.

Source & attribution

This skill is categorized under Creative & Visual and is published by davila7, maintained in davila7/claude-code-templates.

← Browse All Agent Skills
Sponsored AI assistant. Recommendations may be paid.