facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.27k stars 478 forks source link

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

Closed gavinxgu closed 1 year ago

gavinxgu commented 3 years ago

Execute jscodeshift with an error

/usr/bin/env: ‘node\r’: No such file or directory 
machty commented 3 years ago

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
ZhangYiJiang commented 3 years ago

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

roddds commented 3 years ago

This is still an issue in 0.13.0.

michaldudak commented 3 years ago

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

Note that you can't do that if you use Lerna as it creates a bash script in place of the node_modules/.bin/jscodeshift JS file.

fijiwebdesign commented 3 years ago

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"
  },
dijs commented 2 years ago

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.

Krisztiaan commented 2 years ago

You could also use npx jscodeshift instead.

sibelius commented 2 years ago

any workaround on m1?

jediswear commented 1 year ago

any workaround on m1?

@sibelius, works on m1

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

sibelius commented 1 year ago

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

is not working for me

pvinis commented 1 year ago

it gives the same error even with npx jscodeshift.

Daniel15 commented 1 year ago

This is strange... I'm not sure how Windows line endings ended up in the file. I do publish jscodeshift from a Windows PC, but I also publish other things and haven't had an issue with any of the others. Hmm.

dreyks commented 1 year ago

I think the issue is not in the windows line-ending per se, I guess node is smart enough to work with it. what's not smart enough is bash - the \r in the shebang string turns it into #!/usr/bin/env node\r

sibelius commented 1 year ago

here more on this https://techtalkbook.com/env-noder-no-such-file-or-directory/

sibelius commented 1 year ago

anybody can give a try here https://github.com/facebook/jscodeshift/pull/549?