DEV Community

Cover image for env: node\r: No such file or directory
Sibelius Seraphini for Woovi

Posted on

env: node\r: No such file or directory

Some bugs at first view are so weird that you have no idea how to fix it.

We use a lot of jscodeshift codemods here at Woovi, to update old code patterns to new ones, killing our legacy code faster.

The new version of jscodeshift, introduce this weird bug

yarn jscodeshift -t useFragmentCodemod.ts

env: node\r: No such file or directory
Enter fullscreen mode Exit fullscreen mode

Deep diving to find the root cause

Going deep in the node_modules/jscodeshift/bin/jscodeshift.js

We found this:

#!/usr/bin/env node
Enter fullscreen mode Exit fullscreen mode

#! is a shebang
/usr/bin/env makes the script "portable", it will find the executable in the PATH
node the executable to run this script

When we run the script, it complains that it can't find node\r.

Line Break types

Windows use 2 characters to mark the line break CR LF.
Linux uses just 1 LF.

CR - Carriage Return - \r moves the cursor to the beginning of the line without advancing to the next line
LF - Line Feed - \n moves the cursor down to the next line without returning to the beginning of the line

The problem was that someone opened the file using a Windows, and saved using CR LF format instead of only using LF. This turned a "portable" script into a non-portable one.

Landing the fix

I've tried some commands to convert from DOS(Windows) format to Linux one. I decided to just add 2 spaces after node to avoid \r CR to break on mac.

Here is the pull request https://github.com/facebook/jscodeshift/pull/549

Until the fix lands in the next release, you can use this patch-package

diff --git a/node_modules/jscodeshift/bin/jscodeshift.js b/node_modules/jscodeshift/bin/jscodeshift.js
index 559fac6..4875acf 100755
--- a/node_modules/jscodeshift/bin/jscodeshift.js
+++ b/node_modules/jscodeshift/bin/jscodeshift.js
@@ -1,5 +1,7 @@
-#!/usr/bin/env node
+#!/usr/bin/env node  

+// there are 2 spaces after node now
+
 /**
  * Copyright (c) Facebook, Inc. and its affiliates.
  *
Enter fullscreen mode Exit fullscreen mode

To sum up

Do not get afraid of weird bugs, there are always some reasonable explanation of why it is happening.
Usually takes some time to you understand the root cause of it, but you always learning a lot in the process


Woovi
Woovi is a Startup that enables shoppers to pay as they like. To make this possible, Woovi provides instant payment solutions for merchants to accept orders.

If you want to work with us, we are hiring!

Oldest comments (0)