Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova 8: Could not install from "ios" as it does not contain a package.json file

I removed my ios platform and tried to add it back again, but now it says there is a problem and it needs package.json.

How do I fix ios platform so it has a package.json?

Running 8.1.2 (also tried in 8.0) with [email protected]

$ cordova platform add ios
{ Error: npm: Command failed with exit code 1 Error output:
npm ERR! code ENOLOCAL
npm ERR! Could not install from "ios" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mikenelson/.npm/_logs/2018-10-11T09_47_23_544Z-debug.log
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-common/src/superspawn.js:169:23)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
stderr: 'npm ERR! code ENOLOCAL\nnpm ERR! Could not install from "ios" as it does not contain a package.json file.\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /Users/mikenelson/.npm/_logs/2018-10-11T09_47_23_544Z-debug.log\n',
code: 1 }

Update

8 months later I just did the same thing again, but this time I created a folder called 'android' in my project root, just to put some stuff in. So I got:

Could not install from "android" as it does not contain a package.json file

The problem, as Luigi Lopez points out in the comments, is you cannot create a folder called 'ios' or 'android' in the project root. It thinks you are wanting to install the platform from your local folder.

like image 881
mike nelson Avatar asked Oct 11 '18 09:10

mike nelson


4 Answers

I'm not sure it is the same case but I was receiving the same error in a Ionic 4 project and what worked for me was to remove ios/ directory under the project root and re-running the command: ionic cordova platform add ios

Hope it helps.

like image 135
ivissani Avatar answered Oct 24 '22 01:10

ivissani


i was also facing the same issue, seems like if we have already built a capacitor for the particular platform it will throw this error. for me when i removed android capacitor build from the root of the project and when i retried. it started working for me.

like image 22
KBC Avatar answered Oct 24 '22 00:10

KBC


i have same issue after update ionic remove path of

/platforms/android

ionic cordova platform add android
like image 24
Issa Lafi Avatar answered Oct 24 '22 01:10

Issa Lafi


So this frustrated me for about an hour and finally figured out to go into the project directory and delete the folder called "android" and then re ran the command. It forces the installation of android again with all the proper files.

like image 28
kjohnsonthecoder Avatar answered Oct 23 '22 23:10

kjohnsonthecoder