Onesignal plugin with ios platform issue

I got this error while trying to sudo ionic cordova platform add ios !

Osamas-MBP:DawaeyApp osama$ sudo ionic cordova platform add ios --save
> cordova platform add ios --save
✖ Running command - failed!

[ERROR] Cordova encountered an error.
        You may get more insight by running the Cordova command above directly.
        
[ERROR] An error occurred while running cordova platform add ios --save (exit code 1):
        
        Using cordova-fetch for cordova-ios@~4.4.0
        Adding ios project...
        Creating Cordova project for the iOS platform:
        Path: platforms/ios
        Package: com.dawaey
        Name: Dawaey
        iOS project created with cordova-ios@4.4.0
        Installing "onesignal-cordova-plugin" for ios
        Failed to install 'onesignal-cordova-plugin': undefined
        Error: /Library/Ruby/Gems/2.0.0/gems/claide-1.0.2/lib/claide/command.rb:439:in `help!': [!] You cannot run
        CocoaPods as root. (CLAide::Help)
        
        Usage:
        
        $ pod COMMAND
        
        CocoaPods, the Cocoa library package manager.
        
        Commands:
        
        + cache      Manipulate the CocoaPods cache
        + env        Display pod environment
        + init       Generate a Podfile for the current directory
        + install    Install project dependencies according to versions from a
        Podfile.lock
        + ipc        Inter-process communication
        + lib        Develop pods
        + list       List pods
        + outdated   Show outdated project dependencies
        + repo       Manage spec-repositories
        + setup      Setup the CocoaPods environment
        + spec       Manage pod specs
        + update     Update outdated project dependencies and create new Podfile.lock
        
        Options:
        
        --silent     Show nothing
        --version    Show the version of the tool
        --verbose    Show more debugging information
        --no-ansi    Show output without ANSI codes
        --help       Show help banner of specified command
        from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.1/lib/cocoapods/command.rb:47:in `run'
        from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.1/bin/pod:55:in `<top (required)>'
        from /usr/local/bin/pod:23:in `load'
        from /usr/local/bin/pod:23:in `<main>'

Error message is pretty clear: You are running a command with sudo, so as root, that is executing a command itself that may not be run as root.

so why it’s not accepting running ionic cordova platform add ios without sudo !!!?

Osamas-MacBook-Pro:DawaeyApp osama$ ionic cordova platform add ios
> cordova platform add ios --save
✖ Running command - failed!

[ERROR] Cordova encountered an error.
        You may get more insight by running the Cordova command above directly.
        
[ERROR] An error occurred while running cordova platform add ios --save (exit
        code 1):
        
        /usr/local/lib/node_modules/cordova/node_modules/configstore/index.js:54
        throw err;
        ^
        
        Error: EACCES: permission denied, open
        '/Users/osama/.config/configstore/cordova-config.json'
        You don't have access to this file.
        
        at Error (native)
        at Object.fs.openSync (fs.js:641:18)
        at Object.fs.readFileSync (fs.js:509:33)
        at Object.get
        (/usr/local/lib/node_modules/cordova/node_modules/configstore/index.js:35:26)
        at Object.Configstore
        (/usr/local/lib/node_modules/cordova/node_modules/configstore/index.js:28:44)
        at Object.<anonymous>
        (/usr/local/lib/node_modules/cordova/src/cli.js:39:12)
        at Module._compile (module.js:570:32)
        at Object.Module._extensions..js (module.js:579:10)
        at Module.load (module.js:487:32)
        at tryModuleLoad (module.js:446:12)

Because you created something using sudo before, which made the file permissions so that it can only be edited with sudo. Unfortunately for you, the plugin you are adding doesn’t work with sudo. You have to find a way to fix the file permissions.

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config

These commands will allow cordova & ionic cli commands to be used without sudo.

1 Like