Unable to run ionic build ios

I get this error when trying to build ionic for ios… any ideas?

I tried reinstalling cordova, npm, node, ionic-plugin-keyboard… here is my ionic info:
Your system information:

Cordova CLI: 6.3.1
Ionic Framework Version: 1.3.1
Ionic CLI Version: 2.0.0
Ionic App Lib Version: 2.0.0
ios-deploy version: 1.8.6 
ios-sim version: 5.0.8 
OS: Mac OS X El Capitan
Node Version: v6.4.0
Xcode version: Xcode 7.3.1 Build version 7D1014 

when I run the command…
ionic build ios
(node:4572) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
• You’re trying to build for ios but don’t have the platform installed yet.
∆ Installing ios for you.
Installing cordova-plugin-device
Installing cordova-plugin-console
Installing cordova-plugin-whitelist
Installing cordova-plugin-splashscreen
Installing cordova-plugin-statusbar
Installing ionic-plugin-keyboard
Error: Command failed: cordova platform add ios
Error: Platform ios already added.

    at ChildProcess.exithandler (child_process.js:206:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:852:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)

Have you tried using sudo?

yes unfortunately I get the same output

have you try to remove it explicitely first and then to add it again ?

ionic platform rm ios
ionic platform add ios

maybe will help or give you a little bit more clear stacktrace on the error?

ionic platform add ios
(node:7838) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
Running command: /Users/guyhalperin/documents/hooks/before_platform_add/init_directories.js /Users/guyhalperin/documents


Error during untar for /Users/guyhalperin/.cordova/lib/npm_cache/cordova-ios/4.2.0/package.tgz: Error: EACCES: permission denied, open '/Users/guyhalperin/.cordova/lib/npm_cache/cordova-ios/4.2.0/package/.npmignore'


Error: Failed to fetch platform ios
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: EACCES: permission denied, open '/Users/guyhalperin/.cordova/lib/npm_cache/cordova-ios/4.2.0/package/.npmignore'


➜  githubIonics  ionic build ios
(node:7864) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.

Running 'build:before' gulp task before build
[23:33:18] Starting 'clean'...
[23:33:18] 'clean' errored after 38 ms
[23:33:18] Error: EACCES: permission denied, unlink '/Users/guyhalperin/Documents/githubIonics/www/build/app.html'
    at Error (native)
• You're trying to build for ios but don't have the platform installed yet.
∆ Installing ios for you.
Installing cordova-plugin-device
Installing cordova-plugin-console
Installing cordova-plugin-whitelist
Installing cordova-plugin-splashscreen
Installing cordova-plugin-statusbar
Installing ionic-plugin-keyboard
 Error: Command failed: cordova platform add ios
Error: Failed to fetch platform ios
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: EACCES: permission denied, open '/Users/guyhalperin/.cordova/lib/npm_cache/cordova-ios/4.2.0/package/.npmignore'

    at ChildProcess.exithandler (child_process.js:206:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:852:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)

when I run it with sudo I am able to install successfully, but get this when I run ionic build:

 sudo ionic build ios
(node:8014) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.

Running 'build:before' gulp task before build
[23:35:04] Starting 'clean'...
[23:35:04] Finished 'clean' after 43 ms
[23:35:04] Starting 'build'...
[23:35:04] Starting 'sass'...
[23:35:04] Starting 'html'...
[23:35:04] Starting 'fonts'...
[23:35:04] Starting 'scripts'...
[23:35:04] Finished 'html' after 49 ms
[23:35:04] Finished 'scripts' after 50 ms
[23:35:04] Finished 'fonts' after 57 ms
[23:35:05] Finished 'sass' after 944 ms
[23:35:12] Finished 'build' after 7.37 s
[23:35:12] Starting 'build:before'...
[23:35:12] Finished 'build:before' after 4.36 μs

• You're trying to build for ios but don't have the platform installed yet.
∆ Installing ios for you.
Installing cordova-plugin-device
Installing cordova-plugin-console
Installing cordova-plugin-whitelist
Installing cordova-plugin-splashscreen
Installing cordova-plugin-statusbar
Installing ionic-plugin-keyboard
 Error: Command failed: cordova platform add ios
Error: Platform ios already added.

    at ChildProcess.exithandler (child_process.js:206:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:852:16)
    at Socket.<anonymous> (internal/child_process.js:323:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:492:12)

ionic and cordova in command line should not be use with sudo, i think. if you face access problem, you should fix these access to let these command run withtout sudo.

so maybe

  1. ionic platform rm ios
  2. fix access privileges on /Users/guyhalperin/.cordova/lib/npm_cache/cordova-ios/4.2.0/package/.npmignore
  3. ionic platform add ios

is there a good way to fix the access privileges? I can’t seem to get it…

I’m not 100% sure but it’s the way I would try to solve the problem. According your logs some commands doesn’t have enough permissions/privileges to do some actions on your filesystem. So I would have a look at which files can’t be processed and try to fix the permissions (with commands “chmod” and “chown”)

....Error: EACCES: permission denied...

Try running the following command on your directory, this will change the permissions to your regular account so you shouldn’t require sudo to run your commands.

sudo chown -R $USER /your-directory/

This is a common issue people face when using npm in general. Using sudo eventually leads to issues like this and should be avoided.
Credit for command : https://github.com/npm/npm/issues/194#issuecomment-369492

2 Likes

Using sudo is never a solution to a problem.
In fact it can cause more issues.

1 Like

I would recommend you investigate why you need to use sudo. If you have to use sudo with ionic then something is wrong with your permissions.

Running with sudo can do more harm than good (speaking from experience here :slight_smile:)

I had some similar issues with ionic and once I fixed my permissions and stopped using sudo when carrying out ionic commands, things became much easier. :slight_smile:

1 Like