Matheus Macedo
Matheus Macedo

Reputation: 41

/usr/bin/env: 'ts-node-script\r': No such file or directory

I'm trying to run a typescript file but the following error appears:

/usr/bin/env: 'ts-node-script\r': No such file or directory

I have ts-node installed in v10.4.0.

I have node installed in version v17.3.1

Upvotes: 4

Views: 574

Answers (1)

KyleMit
KyleMit

Reputation: 30147

This often occurs when the file was saved on a windows OS with \r\n (CRLF) line endings, but linux / mac os is looking for a \n (LF)

When you run a script with a shebang (e.g. #!/usr/bin/env ts-node-script), the kernel reads up to the first newline \n to figure out which interpreter to invoke. If you have a windows-style carriage return, the \r sneaks into the path so it's technically looking for ts-node-script\r (which it obviously can't find anywhere).

For a quick way to fix the issue, you can install dos2unix and convert your file to use unix style line endings like this:

brew install dos2unix
dos2unix <path-to-file.ts>

See Also: Node script executable not working on Mac : env: node\r: No such file or directory

Upvotes: 0

Related Questions