4

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

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.