jscodeshift: Version: 0.12.0. /usr/bin/env: ‘node\r’: No such file or directory

Execute jscodeshift with an error

/usr/bin/env: ‘node\r’: No such file or directory 

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 46
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Ran into this because I tried to install with yarn via yarn global add jscodeshift, but yarn doesn’t convert windows line endings

You have to install with npm per the readme (npm converts the line endings):

npm install -g jscodeshift

Another workaround is to call the jscodeshift bin in node_modules directly, which bypass the shebang at the top of the script -

node node_modules/.bin/jscodeshift -t ...

This is useful if jscodeshift is being called as part of a script, and the package is installed separately or if it’s not possible to use a different package manager

Still an issue in the latest version. Only way to combat this was to downgrade to 0.11.0 which does not have the same issue.

This is still an issue in 0.13.0.

any workaround on m1?

You can also reference the ./node_modules/.bin/jscodeshift directly in an npm script. eg:

package.js

"scripts": {
    "codeshift": "node ./node_modules/.bin/jscodeshift",
    "start": "yarn codeshift -t ./index.js --stdin < ./sample-files.txt",
    "docs": "yarn codeshift --help",
    "test": "jest"
  },