Fixing "env: node\r: No such file or directory" on mac for an npm package

Photo by Adi Goldstein on Unsplash

If you install an npm package using yarn and you get this error it means that the package author is using windows line endings and Node.js on mac can't run the script as expected.

env: node\r: No such file or directory

To fix it you need to change the line endings. But you need to ensure this happens after each install of packages!

How to change line endings on npm package install

Note: You won't get this error if you use npm because npm automatically processes the line endings for you!

The trick for us yarn users is to use the crlf package to modify the line endings for the package.

You can add a script to the prepare script. This will be run after every install.

  "prepare": "npx crlf --set=LF node_modules/.bin/jira-prepare-commit-msg"

Hey! Are you a developer?

🚀 Set Up Your Dev Environment in Minutes, Not Hours!

Tired of spending hours setting up a new development machine? I used to be, too—until I automated the entire process!

Now, I just run a single script, grab a coffee, and let my setup take care of itself.

Save 30+ hours configuring a new Mac or Windows (WSL) development environment.
Ensure consistency across all your machines.
Eliminate tedious setup and get coding faster!
Get Instant Access →