RyanP13
RyanP13

Reputation: 7753

Cordova after_prepare hook succeeds in Android but fails in iOS

I have written a after_prepare hook for my Cordova build which removes the node_modules folder from the final build:

#!/usr/bin/env node

/**
 * The node modules we want to remove from the build prior to building
 * @type {Array}
 */
var foldersToRemove = ["platforms/android/assets/www/node_modules", "platforms/ios/www/node_modules"];

var fse = require('fs-extra');
var path = require('path');
var rootdir = process.argv[2];

foldersToRemove.forEach(function(folder) {

    var rmFolder = path.join(rootdir, folder);

    fse.remove(rmFolder, function(err) {
        if (err) {
            return console.error(err);
        } else {
            console.log(rootdir);
            console.log("fse folder removed success!")
        }
    });

});

This works for me when i run cordova prepare android -d in in the CLI but upon switching to iOS it fails with the following error:

env: node\r: No such file or directory Hook failed with error code 127:

I have tried with just the reference to the ios platform folder and it issues the same error message.

Upvotes: 7

Views: 3661

Answers (3)

coder2017
coder2017

Reputation: 331

This error can be caused while trying to build your Ionic or Cordova application under OSX and it is most likely due to the line ending format in the file in question. Try this

Upvotes: 0

Loukan ElKadi
Loukan ElKadi

Reputation: 2877

Try this in the terminal on OSX:

tr -d '\r' < FILE_NAME > FILE_NAME

Upvotes: 0

Mthokozisi
Mthokozisi

Reputation: 168

You need to use a text editor like NotePad++

On NotePad++, you will follow these steps:

  • Open the file thats giving you issues
  • Go to 'Find' option and select the 'Replace' tab
  • You should find this string : '\r\n'
  • Replace it with \n
  • Make sure the 'wrap around' option is selected.
  • In the search mode, select 'Extended', and then go ahead and replace all.

  • Save the file and perform the iOS build again

Upvotes: 3

Related Questions