This was my first time using the Ionic Framework to develop hybrid apps. The Framework is not really new to me because it’s build on Angular and Apache Cordova. Yeah! I love AngularJS so does Angular. But when I tried creating my first app by choosing an option in its CLI I got an error when I choose to install cordova.
I didn’t mind the error at first which says
npm ERR! write after end and continued the installation with the other dependencies.
Now, when I tried to integrate additional plugins onto the app I need to use Apache Cordova to install it.
I tried manually installing cordova using the following command but to no avail. I got the same error as mentioned above.
$ npm install -g cordova npm ERR! write after end
So, another problem previously skipped needs to be resolved.
Looking at the error doesn’t really give enough details for me to start with, though I suspect that it might be due to permission or security issues.
I read through Cordova Command-line Interface’s guide in their site and found the following statement.
cordovautility. In Unix, prefixing the additional
sudocommand may be necessary to install development utilities in otherwise restricted directories:
$ sudo npm install -g cordova
And not able to run the above command since I am only using the BASH emulation provided by Git for Windows.
I stumbled upon a discussion in stackoverflow about the issue which is most likely the same as I had. I’ve seen several discussions around the web to use the
--unsafe-perm flag. But what that flag really does?
I looked further in NPM’s miscellaneous configurations and found the following:
- Default: false if running as root, true otherwise
- Type: Boolean
Set to true to suppress the UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.
The account I’m using is an administrator but there are folders that are restricted by default in Windows which may require further User Account Control which is not possible in the command line.
So, given the possible solution above I tried running the following command and waited for quite some time.
$ npm install -g cordova --unsafe-perm C:\Users\omelsoft\AppData\Roaming\npm\cordova -> C:\Users\omelsoft\AppData\Roaming\npm\node_modules\cordova\bin\cordova + [email protected] added 413 packages from 390 contributors in 146.598s
And VOILA! Apache Cordova was successfully installed and can already proceed with Ionic Framework app plugin integration.