env: node\r: No such file or directory

Sandeep Agrawal
2 min readMar 1, 2022

--

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.

Originally published at https://techtalkbook.com on March 1, 2022.

--

--

No responses yet