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

Published on May 18, 2021

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"
Darragh ORiordan

Hi! I'm Darragh ORiordan.

I live and work in Sydney, Australia enjoying the mountains and the ocean.

I build and support happy teams that create high quality software for the web.

Contact me on Twitter!

Sign up for the newsletter

Get new writings, curated tech articles and coding tips!

Read the Privacy Policy.