Skip to content

fix: ensure motia CLI is built before workspace bin linking#1289

Open
addy1947 wants to merge 1 commit intoiii-hq:mainfrom
addy1947:fix/motia-cli-bin
Open

fix: ensure motia CLI is built before workspace bin linking#1289
addy1947 wants to merge 1 commit intoiii-hq:mainfrom
addy1947:fix/motia-cli-bin

Conversation

@addy1947
Copy link

@addy1947 addy1947 commented Mar 11, 2026

Fixes #1179

Summary

Fix monorepo build failure where the motia CLI binary is unavailable during workspace installation.

The motia package exposes a CLI through the bin field pointing to dist/new/cli.mjs, but this file is generated only after running the build. During pnpm install, pnpm attempts to create the workspace binary symlink before the file exists, causing the playground build to fail with motia: not found.

This change adds a prepare script to ensure the CLI is built before pnpm links the binary.


How it works

Fix

Add a prepare script in:

frameworks/motia/motia-js/packages/motia/package.json
"scripts": {
  "build": "tsdown",
  "prepare": "pnpm build",
  "test": "jest --selectProjects unit",
  "test:unit": "jest --selectProjects unit",
  "test:coverage": "jest --selectProjects unit --coverage --coverageReporters=text",
  "test:integration": "jest --selectProjects integration",
  "test:ci": "jest"
}

What this does

  • prepare runs automatically during pnpm install
  • Ensures dist/new/cli.mjs is generated before pnpm creates workspace binary links
  • Allows pnpm to correctly create:
node_modules/.bin/motia

Result

The playground package can successfully execute:

motia build

and the entire monorepo build completes without errors.


Test plan

Before the fix

  1. Clone the repository:
git clone https://github.com/MotiaDev/motia.git
cd motia/motia-js
  1. Install dependencies and build:
pnpm install
pnpm build

Result:

The build fails during the playground step with the error:

playground build$ motia build
sh: 1: motia: not found

This happens because the CLI binary is not generated before pnpm tries to link it.


After the fix

  1. Clone the repository:
git clone https://github.com/MotiaDev/motia.git
cd motia/motia-js
  1. Modify the file:
frameworks/motia/motia-js/packages/motia/package.json

Add the prepare script.

  1. Run the installation and build again:
pnpm install
pnpm build

Result:

  • dist/new/cli.mjs is generated during installation
  • node_modules/.bin/motia is created successfully
  • Playground package runs motia build without errors
  • Entire monorepo builds successfully

Summary by CodeRabbit

  • Chores
    • Updated build configuration to automatically run during package installation.

@vercel
Copy link
Contributor

vercel bot commented Mar 11, 2026

@kumaridivya5 is attempting to deploy a commit to the motia Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

Added a prepare npm lifecycle script to the motia package that executes pnpm build after installation. This ensures the package builds automatically during the install phase.

Changes

Cohort / File(s) Summary
Build Configuration
frameworks/motia/motia-js/packages/motia/package.json
Added prepare lifecycle script with pnpm build command to trigger automatic package building after installation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested reviewers

  • andersonleal

Poem

🐰 A tiny script so neat and small,
The prepare command runs for all,
Build on install without delay,
No more hardcoded paths to slay! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix: ensure motia CLI is built before workspace bin linking' accurately describes the main change: adding a prepare script to build the CLI before pnpm creates bin symlinks.
Linked Issues check ✅ Passed The code change (adding prepare script) directly addresses the root cause in #1179 by ensuring dist/new/cli.mjs exists before pnpm attempts to create workspace bin links.
Out of Scope Changes check ✅ Passed The change is tightly scoped to the objective: only adds a prepare script to motia's package.json with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
frameworks/motia/motia-js/packages/motia/package.json (2)

25-25: Consider the performance impact of building on every install.

The prepare hook runs on every pnpm install, which means developers will experience build overhead whenever they:

  • Switch branches with different dependencies
  • Run pnpm install to update dependencies
  • Clone the repository fresh

If the tsdown build takes several seconds, this adds friction to common development workflows.

Alternatives to consider:

  • postinstall instead of prepare: Runs after install but not before publish; may still solve the bin symlink issue with less overhead
  • Separate the CLI: Extract the CLI into a standalone package that doesn't require a build step (e.g., keep source as .mjs)
  • Pre-commit hooks: Build the CLI via a pre-commit hook and commit the built artifact (though this adds built files to git)

The current approach is simple and fixes the immediate problem, but consider whether the install-time overhead is acceptable for your team's workflow.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frameworks/motia/motia-js/packages/motia/package.json` at line 25, The
package.json currently runs "pnpm build" in the prepare script which triggers a
build on every pnpm install; remove or replace this to avoid install-time build
overhead by either (A) changing the script key "prepare": "pnpm build" to
"postinstall": "pnpm build" if you only want builds after installs (not before
publish), (B) remove the prepare script and document building in
contributor/developer docs, or (C) extract the CLI into a separate package that
ship-bundles the built artifact; update the "prepare" entry in package.json (the
"prepare" script key) accordingly and ensure any consumers of the package still
receive the needed built assets (or add a postinstall step or CI/publish
generation as appropriate).

25-25: Consider updating CI workflows to avoid duplicate builds.

The prepare hook will cause motia to be built during pnpm install --frozen-lockfile. However, CI workflows (context snippets 1 and 3) explicitly build motia again after installation:

- name: Install dependencies
  run: pnpm install --frozen-lockfile  # Triggers prepare → builds motia

- name: Build Motia
  run: pnpm --filter motia build  # Redundant build

This creates duplicate builds in CI, wasting compute resources and time. Consider either:

  • Update CI workflows to skip the explicit pnpm --filter motia build step (rely on prepare hook)
  • Use --ignore-scripts during install and keep explicit builds (but then loses the bin fix locally)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frameworks/motia/motia-js/packages/motia/package.json` at line 25, The
prepare script in package.json ("prepare": "pnpm build") causes motia to be
built during pnpm install, creating a duplicate build when CI later runs pnpm
--filter motia build; either remove the explicit CI step that runs pnpm --filter
motia build (rely on the prepare hook) or change the install step to pnpm
install --frozen-lockfile --ignore-scripts and keep the explicit pnpm --filter
motia build; update the CI job accordingly to use one of these two approaches
and document the chosen approach in the workflow comments so maintainers know
why the build step was removed or why --ignore-scripts is used.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@frameworks/motia/motia-js/packages/motia/package.json`:
- Line 25: The package.json currently runs "pnpm build" in the prepare script
which triggers a build on every pnpm install; remove or replace this to avoid
install-time build overhead by either (A) changing the script key "prepare":
"pnpm build" to "postinstall": "pnpm build" if you only want builds after
installs (not before publish), (B) remove the prepare script and document
building in contributor/developer docs, or (C) extract the CLI into a separate
package that ship-bundles the built artifact; update the "prepare" entry in
package.json (the "prepare" script key) accordingly and ensure any consumers of
the package still receive the needed built assets (or add a postinstall step or
CI/publish generation as appropriate).
- Line 25: The prepare script in package.json ("prepare": "pnpm build") causes
motia to be built during pnpm install, creating a duplicate build when CI later
runs pnpm --filter motia build; either remove the explicit CI step that runs
pnpm --filter motia build (rely on the prepare hook) or change the install step
to pnpm install --frozen-lockfile --ignore-scripts and keep the explicit pnpm
--filter motia build; update the CI job accordingly to use one of these two
approaches and document the chosen approach in the workflow comments so
maintainers know why the build step was removed or why --ignore-scripts is used.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c6fe4643-4344-4ca8-8e5a-13555445ebde

📥 Commits

Reviewing files that changed from the base of the PR and between 8eaaa06 and 0ff21ca.

📒 Files selected for processing (1)
  • frameworks/motia/motia-js/packages/motia/package.json

@addy1947
Copy link
Author

Hey @rohitg00, I tried to fix the issue you reported regarding the error during the build. I made some changes that seem to resolve the problem on my side. Could you please take a look and verify if it works for you as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Playground build fails: hardcoded absolute path in CLI resolution

2 participants