In this article, we will learn how to fix an issue related to node\r: No such file or directory.
Cause of “env: node\r: No such file or directory”
- This problem happens mostly in the Mac/Linux operating system if the node tries to execute a js file having windows-style line endings.
- The line endings get changed to CRLF(windows style) instead of LS (Unix) so the parser takes the newline character as part of the path because of this character ‘\ R’.
- It usually comes from third-party npm packages having js files.
How to fix it?
- To fix this problem of “env: node\r: No such file or directory” just change the line feed method CRLF to LF. Run the below command from your terminal for this:
$brew install dos2unix
$find /usr/local/lib/node_modules -name "*.js" | xargs sudo dos2unix
Note: In the above second command, replace “/usr/local/lib/node_modules
” with your node_module package path. - Sometimes you may also find this issue with Git that its config is set to AUTOCRLF so you can run the below command in your terminal:
git config --global core.autocrlf input
This setting is generally used on Unix/Linux/OS X to prevent CRLFs from getting written into the repository.
I hope you like this article and helps you to solve your problems.
Visit Techtalkbook to find more related topics.
References
- https://debugah.com/tag/env-noder-no-such-file-or-directory
- https://github.com/TarikHuber/rmw-shell/issues/20
- https://newbedev.com/node-script-executable-not-working-on-mac-env-node-r-no-such-file-or-directory
- https://stackoverflow.com/questions/30344858/node-script-executable-not-working-on-mac-env-node-r-no-such-file-or-directo