Error: Hook failed with error code 127

I was getting this error off and on. It caused a bunch of delays for me so wanted to post to help out if someone else was running into this.

Error

On OSX Mavericks after ionic build/run ios

> ionic build ios
env: node\r: No such file or directory
Error: Hook failed with error code 127: /hooks/after_prepare/010_add_platform_class.js

Issue

This is due to to OSX ^M line endings that were committed to my project in this file. For some reason they seem to pop up in this file only, although I have seen some SO posts where people are having the problem on other node scripts.

Fix

# check if the file has ^M line endings
cat -v FILE-NAME-WITH-ERROR

# fix the file
tr -d '\r' < FILE-NAME-WITH-ERROR > FILE-NAME-WITH-ERROR.fix

# check if problem fixed in resulting file from above
cat -v FILE-NAME-WITH-ERROR.fix

# overwrite original file with fixed file
mv FILE-NAME-WITH-ERROR.fix  FILE-NAME-WITH-ERROR

Hope this helps.

2 Likes

Hmm, I had been using mavericks and yosomite without having any issues. Any other info you could provide?

Seems that this error is presenting in hooks coded in Windows. I’ve found this error, too.

If you want there is a faster solution, especially if you have many files to fix.

Open the file in vi and go for:

:set fileformat=unix

:w

Hope this helps!

2 Likes

That will correct the specific file in that specific build but will not stop it from happening every time you try and launch your project in the iOS simulator. I’m having the same issue but others on my team is not … any ideas on what’s causing this and how to fix it from happening?

what did you mean by FILE-NAME-WITH-ERROR and FILE-NAME-WITH-ERROR .fix , what is fix ,
if i have filex.js is the file error what the commands will be ?

Hello guys,
Same issue. Just delete the hooks folder.

So the hooks folder is not needed at all

Nope. Didn’t help. Still getting the same error…

Hi, maybe this is due to OSX ^M line endings.

check if the file has ^M line endings

cat -v FILE-NAME-WITH-ERROR

fix the file

tr -d ‘\r’ < FILE-NAME-WITH-ERROR > FILE-NAME-WITH-ERROR.fix

check if problem fixed in resulting file from above

cat -v FILE-NAME-WITH-ERROR.fix

overwrite original file with fixed file

mv FILE-NAME-WITH-ERROR.fix FILE-NAME-WITH-ERROR

Οr make a clean build.

I removed and reinstalled ios platform. problem solved!