Skip to content

fix(cli): resolve bin path from cwd to support monorepo workspace hoisting#7315

Open
Aaron3312 wants to merge 1 commit intorefinedev:mainfrom
Aaron3312:fix/cli-resolve-bin-workspace-hoisting
Open

fix(cli): resolve bin path from cwd to support monorepo workspace hoisting#7315
Aaron3312 wants to merge 1 commit intorefinedev:mainfrom
Aaron3312:fix/cli-resolve-bin-workspace-hoisting

Conversation

@Aaron3312
Copy link

@Aaron3312 Aaron3312 commented Mar 1, 2026

PR Checklist

Bugs / Features

What is the current behavior?

When running refine dev inside a monorepo workspace (npm workspaces, yarn workspaces, or Bun), the CLI crashes with:

Error: Cannot find module '.bin/vite'

resolveBin() used require.resolve('.bin/<name>') which resolves relative to the CLI module's own location inside node_modules. In a workspace setup, the CLI lives in a different node_modules subtree than the project binaries (e.g. vite), so the binary is never found.

What is the new behavior?

resolveBin() now walks up the directory tree starting from process.cwd(), checking each node_modules/.bin/<name> until the binary is found. This correctly handles the workspace hoisting case where the binary lives in a parent directory's node_modules/.bin/.

On Windows, both .exe and .cmd extensions are checked. The original require.resolve behavior is kept as a fallback for backward compatibility.

fixes #7314

Notes for reviewers

The fix is minimal and contained entirely in packages/cli/src/commands/runner/projectScripts.ts. Three new tests covering the standard and monorepo scenarios were added to projectScripts.test.ts.

@Aaron3312 Aaron3312 requested a review from a team as a code owner March 1, 2026 09:42
@changeset-bot
Copy link

changeset-bot bot commented Mar 1, 2026

🦋 Changeset detected

Latest commit: 15ce85f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@refinedev/cli Patch
@refinedev/devtools Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@alicanerdurmaz alicanerdurmaz left a comment

Choose a reason for hiding this comment

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

Hi, thanks for improving Refine.

Everything looks great except changeset file names should be auto-generated.

@refinedev refinedev deleted a comment from Moses-main Mar 5, 2026
…sting

When using npm/bun/yarn workspaces, packages are hoisted to a parent
node_modules. The previous require.resolve('.bin/<name>') resolved
relative to the CLI module location, which fails when the CLI is
installed in a different node_modules subtree than the project binaries.

resolveBin() now walks up from process.cwd() searching each
node_modules/.bin/ until the binary is found, falling back to the
original require.resolve behavior for backward compatibility.

On Windows, both .exe and .cmd extensions are checked.

Fixes refinedev#7314
@Aaron3312 Aaron3312 force-pushed the fix/cli-resolve-bin-workspace-hoisting branch from a27a555 to 15ce85f Compare March 5, 2026 21:54
@Aaron3312
Copy link
Author

Thanks for the review! I've renamed the changeset file to an auto-generated name (eleven-needles-teach.md).

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.

[BUG] MODULE_NOT_FOUND: Cannot find module '.bin/vite' when running refine dev in npm/bun workspaces

2 participants