Skip to content

fix: move ajv to dependencies and auto-install deps in install scripts#858

Merged
affaan-m merged 2 commits into
affaan-m:mainfrom
sliver2er:fix/install-missing-ajv-dependency
Mar 29, 2026
Merged

fix: move ajv to dependencies and auto-install deps in install scripts#858
affaan-m merged 2 commits into
affaan-m:mainfrom
sliver2er:fix/install-missing-ajv-dependency

Conversation

@sliver2er

@sliver2er sliver2er commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Move ajv from devDependencies to dependencies — it is required at runtime by the installer (scripts/lib/install/config.js) but was missing for end users
  • Add auto npm install in install.sh when node_modules is missing (fresh git clone)
  • Add matching auto-install in install.ps1 for Windows parity

Fixes Error: Cannot find module 'ajv' when running ./install.sh from a fresh clone.

Type

  • Bug fix

Testing

  • Verified ./install.sh typescript python works on a fresh clone without manual npm install
  • Existing test suite passes (1567/1570, 3 pre-existing failures unrelated to this change)

Checklist

  • Follows format guidelines
  • Tested with Claude Code
  • No sensitive info (API keys, paths)
  • Clear descriptions

Summary by cubic

Move ajv to runtime deps and auto-install Node deps in the install scripts so fresh clones can run the installer without errors. Also stop the Windows installer if npm install fails.

  • Bug Fixes
    • Move ajv from devDependencies to dependencies (used at runtime by scripts/lib/install/config.js).
    • In install.sh and install.ps1, auto-run npm install when node_modules is missing; on Windows, exit early if the install fails.

Written for commit 4eaee83. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Improved first-run installation: setup now automatically detects missing dependencies and installs them when running from fresh clones, providing clearer status and failing fast on install errors to ensure a reliable bootstrap experience.
    • Moved ajv to runtime dependencies so it is installed for consumers by default.

`ajv` is required at runtime by the installer (`scripts/lib/install/config.js`)
but was listed under `devDependencies`. This caused `Error: Cannot find module
'ajv'` when running `./install.sh` from a fresh git clone or via `npx`.

- Move `ajv` from devDependencies to dependencies in package.json
- Add auto `npm install` in install.sh when node_modules is missing
- Add matching auto-install in install.ps1 for Windows parity
@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ca3a38f2-53c0-4558-aec5-d80fe9298fb4

📥 Commits

Reviewing files that changed from the base of the PR and between 9c381b4 and 4eaee83.

📒 Files selected for processing (1)
  • install.ps1

📝 Walkthrough

Walkthrough

The install wrappers (PowerShell and shell) now auto-run npm install in the script directory when node_modules is missing before invoking the Node installer; package.json moves ajv from devDependencies to dependencies.

Changes

Cohort / File(s) Summary
Install Script Wrappers
install.ps1, install.sh
Added pre-execution check for node_modules under the script directory; if absent, temporarily cd into the script dir and run npm install --no-audit --no-fund --loglevel=error before invoking the Node installer. install.ps1 uses try/finally to restore the original directory.
Dependency Classification
package.json
Moved "ajv": "^8.18.0" from devDependencies to dependencies, making it a runtime dependency.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Wrapper as "install.{sh,ps1}"
    participant FS as "filesystem (node_modules)"
    participant NPM as "npm"
    participant Node as "node (install-apply.js)"

    User->>Wrapper: run installer
    Wrapper->>FS: check for `node_modules` in script dir
    alt node_modules missing
        Wrapper->>NPM: npm install (--no-audit --no-fund --loglevel=error)
        NPM-->>Wrapper: exit code
        Wrapper->>FS: restore original cwd (try/finally)
    end
    Wrapper->>Node: node scripts/install-apply.js `@args`
    Node-->>User: exit status
Loading

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly Related PRs

Poem

🐰 I hopped the repo lane tonight,

Checked for modules hidden from sight.
If none were found, I called npm dear,
Installed dependencies, then smiled ear to ear.
ajv now joins the runtime cheer—hooray, let's build and hear!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: moving ajv to dependencies and adding auto-install functionality to the install scripts.
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

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.

@greptile-apps

greptile-apps Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a "Cannot find module 'ajv'" error on fresh git clones by moving ajv from devDependencies to dependencies (it's used at runtime by scripts/lib/install/config.js) and adding automatic npm install to both install.sh and install.ps1 when node_modules is absent.

  • package.json: Moving ajv to dependencies is the correct fix — without it, npm-installed end-users would never install ajv.
  • install.sh: Implementation is correct. The subshell (cd ... && npm install) inside the if body is guarded by set -euo pipefail, so a failed install aborts the script before reaching the Node entry-point.
  • install.ps1: The $LASTEXITCODE check addresses the error-handling gap from prior review, but Write-Error throws immediately (because $ErrorActionPreference = 'Stop' is active), making the subsequent exit $LASTEXITCODE dead code. The script does abort on failure, but it exits with code 1 (unhandled exception) rather than npm's actual exit code.

Confidence Score: 4/5

Safe to merge after fixing the dead exit $LASTEXITCODE in install.ps1 for correct exit-code propagation.

The core bug (missing ajv in runtime deps) is correctly fixed, and the auto-install logic works as intended. The one remaining issue — exit $LASTEXITCODE being unreachable in the PowerShell script due to Write-Error throwing first — is a P2 concern about exit-code accuracy rather than correctness of the install flow itself.

install.ps1 — exit $LASTEXITCODE on line 47 is dead code; replace Write-Error with Write-Host to let it run.

Important Files Changed

Filename Overview
install.ps1 Adds auto-install of Node deps when node_modules is missing; exit-code check is present but exit $LASTEXITCODE is dead code due to Write-Error throwing before it runs.
install.sh Adds auto-install of Node deps when node_modules is missing; set -euo pipefail correctly aborts the script on npm failure.
package.json Moves ajv from devDependencies to dependencies — correct fix since it is required at runtime by the installer.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A([User runs install.sh / install.ps1]) --> B{node_modules exists?}
    B -- No --> C[npm install --no-audit --no-fund]
    C -- success --> D[exec node install-apply.js]
    C -- failure --> E([Exit with error])
    B -- Yes --> D
    D --> F([Installer runs])

    style E fill:#f88,stroke:#c00
    style F fill:#8f8,stroke:#080
Loading

Reviews (2): Last reviewed commit: "fix(install): stop after npm bootstrap f..." | Re-trigger Greptile

Comment thread install.ps1 Outdated
Comment thread install.sh
Comment on lines +18 to +21
if [ ! -d "$SCRIPT_DIR/node_modules" ]; then
echo "[ECC] Installing dependencies..."
(cd "$SCRIPT_DIR" && npm install --no-audit --no-fund --loglevel=error)
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 node_modules directory check may miss partial installs

The guard [ ! -d "$SCRIPT_DIR/node_modules" ] only triggers auto-install when node_modules does not exist at all. A stale or partial node_modules directory (e.g., created by a previously interrupted npm install) won't satisfy the condition, and the script will proceed directly to the Node entry-point, still hitting Cannot find module 'ajv'.

A more reliable sentinel is the package-lock or the specific package directory:

Suggested change
if [ ! -d "$SCRIPT_DIR/node_modules" ]; then
echo "[ECC] Installing dependencies..."
(cd "$SCRIPT_DIR" && npm install --no-audit --no-fund --loglevel=error)
fi
if [ ! -d "$SCRIPT_DIR/node_modules" ] || [ ! -d "$SCRIPT_DIR/node_modules/ajv" ]; then
echo "[ECC] Installing dependencies..."
(cd "$SCRIPT_DIR" && npm install --no-audit --no-fund --loglevel=error)
fi

The same consideration applies to install.ps1 (line 39).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
install.ps1 (1)

37-44: Consider checking npm install exit code before proceeding.

If npm install fails (e.g., network error, missing npm), the script continues to run the installer anyway, which will likely fail with a confusing error. With $ErrorActionPreference = 'Stop', native command failures don't automatically throw.

♻️ Proposed fix to handle npm install failure
 if (-not (Test-Path -LiteralPath $nodeModules)) {
     Write-Host '[ECC] Installing dependencies...'
     Push-Location $scriptDir
-    try { & npm install --no-audit --no-fund --loglevel=error }
+    try {
+        & npm install --no-audit --no-fund --loglevel=error
+        if ($LASTEXITCODE -ne 0) {
+            Write-Error "npm install failed with exit code $LASTEXITCODE"
+            exit $LASTEXITCODE
+        }
+    }
     finally { Pop-Location }
 }

Note: The static analysis warning about Write-Host is a false positive here—it's appropriate for user-facing progress messages in an installer script.

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

In `@install.ps1` around lines 37 - 44, The install block that runs npm install
(checking $nodeModules and using Push-Location/$scriptDir) currently ignores
failures from the native npm command; update the try/finally to capture and
check the npm exit status (use $LASTEXITCODE or $? after the & npm install call)
and if it indicates failure, log an error with Write-Host or Write-Error
including the exit code and stop the script (e.g., throw or exit 1) so the
installer does not continue on failed dependency installation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@install.ps1`:
- Around line 37-44: The install block that runs npm install (checking
$nodeModules and using Push-Location/$scriptDir) currently ignores failures from
the native npm command; update the try/finally to capture and check the npm exit
status (use $LASTEXITCODE or $? after the & npm install call) and if it
indicates failure, log an error with Write-Host or Write-Error including the
exit code and stop the script (e.g., throw or exit 1) so the installer does not
continue on failed dependency installation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6b9aec56-83a4-406e-a5a4-f4ec81d7cb2b

📥 Commits

Reviewing files that changed from the base of the PR and between df4f2df and 9c381b4.

📒 Files selected for processing (3)
  • install.ps1
  • install.sh
  • package.json

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="install.ps1">

<violation number="1" location="install.ps1:42">
P2: `npm install` failures are not checked, so a non-zero exit can be ignored and the script continues into `node install-apply.js` with missing dependencies.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread install.ps1 Outdated
@lukasallau8-collab

Copy link
Copy Markdown

I really need help

@affaan-m affaan-m merged commit b6e3434 into affaan-m:main Mar 29, 2026
2 of 3 checks passed

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="install.ps1">

<violation number="1" location="install.ps1:45">
P2: `Write-Error` is terminating under `$ErrorActionPreference = 'Stop'`, so the script can abort before `exit $LASTEXITCODE`, losing npm’s exit code.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread install.ps1
try {
& npm install --no-audit --no-fund --loglevel=error
if ($LASTEXITCODE -ne 0) {
Write-Error "npm install failed with exit code $LASTEXITCODE"

@cubic-dev-ai cubic-dev-ai Bot Mar 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Write-Error is terminating under $ErrorActionPreference = 'Stop', so the script can abort before exit $LASTEXITCODE, losing npm’s exit code.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At install.ps1, line 45:

<comment>`Write-Error` is terminating under `$ErrorActionPreference = 'Stop'`, so the script can abort before `exit $LASTEXITCODE`, losing npm’s exit code.</comment>

<file context>
@@ -39,7 +39,13 @@ $nodeModules = Join-Path -Path $scriptDir -ChildPath 'node_modules'
+    try {
+        & npm install --no-audit --no-fund --loglevel=error
+        if ($LASTEXITCODE -ne 0) {
+            Write-Error "npm install failed with exit code $LASTEXITCODE"
+            exit $LASTEXITCODE
+        }
</file context>
Suggested change
Write-Error "npm install failed with exit code $LASTEXITCODE"
Write-Error -ErrorAction Continue "npm install failed with exit code $LASTEXITCODE"
Fix with Cubic

peiking88 pushed a commit to peiking88/everything-claude-code that referenced this pull request Apr 4, 2026
…v-dependency

fix: move ajv to dependencies and auto-install deps in install scripts
FrancescoRosciano pushed a commit to FRosciano-Mambo/everything-claude-code that referenced this pull request Jun 1, 2026
…v-dependency

fix: move ajv to dependencies and auto-install deps in install scripts
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.

3 participants