Heather Roberts
Heather Roberts

Reputation: 2138

Cannot run node executable with #!/usr/bin/env node

I am trying to write my own npm executable, but on installing the dependency in another project when I try and run the executable I see the error

$ node_modules/.bin/html-linter    
: No such file or directory

The file does exist and has the node shebang at the top (I copied exactly what the tslint executable had)

If I call it like

$ node node_modules/.bin/html-linter

It works perfectly, but I don't want to have to do that

My executable just looks like:

#!/usr/bin/env node

require('../lib/html-linter-cli');

The path is fine, if I run /usr/bin/env node in my console it works, if I run node --version I get a normal output.

If you want to install the package from npm you can, it is called html-linter

Upvotes: 2

Views: 3374

Answers (1)

Alexander O'Mara
Alexander O'Mara

Reputation: 60507

See the full error message (which is unfortunately being obscured in your Terminal):

$ node_modules/.bin/html-linter
env: node\r: No such file or directory

The \r means you have a carriage return in the shebang line, likely due to Windows-style line endings (in your case, this character caused your Terminal to restart the line, overwriting part of the error and making it harder to see). The file command confirms this.

$ file node_modules/.bin/html-linter
node_modules/.bin/html-linter: a /usr/bin/env node script text executable, ASCII text, with CRLF line terminators

Solution: Don't use Windows line endings (pretty much ever) and save your files with Unix-style LF endings. Any decent code editor should have this option.

Upvotes: 3

Related Questions