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

When attempting to run “ionic cordova prepare ios”, I am returned with the following error:

{ 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/southark/.npm/_logs/2019-07-11T20_15_13_124Z-debug.log
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-common/src/superspawn.js:135:23)
at ChildProcess.emit (events.js:198:13)
at maybeClose (internal/child_process.js:982:16)
at Socket.stream.socket.on (internal/child_process.js:389:11)
at Socket.emit (events.js:198:13)
at Pipe._handle.close (net.js:606:12)
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/southark/.npm/_logs/2019-07-11T20_15_13_124Z-debug.log\n’,
code: 1 }
[ERROR] An error occurred while running subprocess cordova.

    cordova platform add ios --save exited with exit code 1.
    
    Re-running this command with the --verbose flag may provide more information.

Looks like you added Capacitor to your project and added iOS platform to it, or you have an ios folder on the root of your project that confuses Cordova.
So just rename the ios folder, run the prepare command and rename it back (or remove it if not using it)

9 Likes

I landed here because I got this error:

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

and thanks to your comment, I renamed the folder android (that capacitor had added in the root of my project), then ran the command again and it succeeded!
Thank you @jcesarmobile

3 Likes

I too facing same problem, were you able to fix it ?

1 Like

yes, is it possible for you to try the solution explained above?

Please see:

Thanks

any solution ? the same error with me

have you checked the solutions proposed above? there are few that work…