Reputation: 22136
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.
Upvotes: 28
Views: 19954
Reputation: 2664
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
Upvotes: 94
Reputation: 1030
If at some point I add capacitor with cordova the capacitor-generated [android|ios] directory interferes with cordova, I recommend backing up the android directory and removing it. this will solve the problem.
zip –r [android|ios].zip [android|ios]
rm -R [android|ios]
ionic cordova platform remove [android|ios]
ionic cordova platform add [android|ios] --save
unzip [android|ios].zip
rm [android|ios].zip #or add in the .gitignore [android|ios].zip
Upvotes: 0
Reputation: 1
I had the same problem, the reason it was i trying to add an electron platform to cordova, however there was a folder called electron out of platforms folder, exact on the root, for other purposes, I believe there is some conflict, for that I renamed this folder with the name electron2 and cordova add the platform normally.
Upvotes: -1
Reputation: 181
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.
Upvotes: 1
Reputation: 355
i have same issue after update ionic remove path of
/platforms/android
ionic cordova platform add android
Upvotes: 2
Reputation: 71
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.
Upvotes: 7