cordovacordova-ios

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 cordova-ios@4.5.4

$ 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.


Solution

  • 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