Capacitor: command not found: cap

Created on 23 May 2020  路  4Comments  路  Source: ionic-team/capacitor

Description of my problem:
I have an issue with installing capacitor.

I have node.js installed on my mac but when I run "npx cap init" I get "command not found: cap".
I tried everything to solve this issue I also tried removing nodejs completely and reinstalling node, npn, and npx but the issue is still here.

I could use some help here.

Info;
OS: MacOS Catalina v10.15.4
Capacitor version: v2.1.0
node version: v14.3.0
npm/ npx version: v6.14.5

package.json:
{
"name": "new-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@capacitor/cli": "^2.1.0",
"@capacitor/core": "^2.1.0",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

Steps to reproduce:

  1. create-react-app new-app
  2. cd new-app/ npm run start/ quite server (control + c)/ npm run build
  3. npm install --save @capacitor/core @capacitor/cli
  4. npx cap init

Result:
user@user-mbpro new-app % npx cap init
command not found: cap
user@user-mbpro new-app %

Most helpful comment

We recommend installing the CLI locally so that it can be versioned properly with the rest of the Capacitor packages (it should be the same version as core, android, and ios). Installing core globally especially doesn't make sense because it will never be used.

All 4 comments

Installed @capacitor/core @capacitor/cli globaly and now it works

I can't reproduce, but installing cli and core globally is a bad idea.

Maybe it's related to react using yarn instead of npm? try installing with yarn add instead of npm install.
Also, you can use yarn cap init instead of npx cap init

@jcesarmobile This issue has been closed, so no pressure to answer this, but out of curiosity: why is it a bad idea to install cli and core globally?

We recommend installing the CLI locally so that it can be versioned properly with the rest of the Capacitor packages (it should be the same version as core, android, and ios). Installing core globally especially doesn't make sense because it will never be used.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicobytes picture nicobytes  路  3Comments

natevw picture natevw  路  3Comments

Kepro picture Kepro  路  3Comments

gnesher picture gnesher  路  3Comments

json-derulo picture json-derulo  路  3Comments