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.
Error: Cannot find module '@capacitor/cli'
Require stack:
- /home/runner/work/app/app/node_modules/.bin/capCommon 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
- Run
npm ciwithout omitting dev dependencies. - Confirm
@capacitor/cliis listed in package.json devDependencies. - Then call
npx cap sync.
- run: npm ci
- run: npx cap --version
- run: npx cap syncAdd 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.
npm install --save-dev @capacitor/cliHow 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.