Skip to content
Latchkey

Capacitor "Cannot find module '@capacitor/cli'" in CI

The cap command is provided by the @capacitor/cli package. When it is not in node_modules - because install was skipped, was a production-only install, or the package is missing from package.json - Node throws "Cannot find module" the moment npx tries to run it.

What this error means

npx cap sync fails with "Error: Cannot find module '@capacitor/cli'" and a Node stack trace, or npx tries to download a different package because nothing local matched.

Node
Error: Cannot find module '@capacitor/cli'
Require stack:
- /home/runner/work/app/app/node_modules/.bin/cap

Common causes

Dependencies were not installed

CI ran npx cap before npm ci, or a caching step restored an incomplete node_modules without @capacitor/cli.

The CLI is a devDependency but install was production-only

@capacitor/cli is usually a devDependency. With npm ci --omit=dev or NODE_ENV=production, it is skipped and the binary is absent.

How to fix it

Install all dependencies before cap commands

  1. Run npm ci without omitting dev dependencies.
  2. Confirm @capacitor/cli is listed in package.json devDependencies.
  3. Then call npx cap sync.
.github/workflows/ci.yml
- run: npm ci
- run: npx cap --version
- run: npx cap sync

Add the CLI if it is missing

If the package is not declared, install it so npx resolves it locally instead of attempting a remote fetch.

Terminal
npm install --save-dev @capacitor/cli

How to prevent it

  • Keep @capacitor/cli in devDependencies and never omit dev in build jobs.
  • Run npm ci on a clean runner before any cap invocation.
  • Verify with npx cap --version early to fail fast.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →