Node script executable not working on Mac : env: node\r: No such file or directory

After all, I found the solution to my problem.

As my node script file has been created on Windows, the file is DOS format (line endings in DOS format I think). So, I used a module which allow to converting a file to a unix format :

brew install dos2unix
sudo dos2unix /usr/local/lib/node_modules/task-app/src/task-app.js

You could also use vim:

vim script

:se ff=unix
:wq

That will confirm DOS-style newlines to Unix-style newlines.


There is a problem with newlines in your script. Make sure that #!/usr/bin/env node is followed by \n (unix style) instead of \r\n (windows/dos style). To fix that, use the tr command to remove \r's from your file:

cat your_script.js | tr -d '\r' > fixed_script.js