Line endings break cli.js on Unix Machines
See original GitHub issueAfter I upgraded a project to npm-watch@0.1.2, it was blowing up on me with the following error:
> npm-watch
/usr/bin/env: ‘node\r’: No such file or directory
npm ERR! Linux 4.4.5-1-ARCH
npm ERR! argv "/home/joe/.nvm/versions/node/v4.4.1/bin/node" "/home/joe/.nvm/versions/node/v4.4.1/bin/npm" "run" "watch"
npm ERR! node v4.4.1
npm ERR! npm v3.8.3
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! supwithnpm-watch@1.0.0 watch: `npm-watch`
npm ERR! spawn ENOENT
So I cloned this repo, did a npm link and it worked fine, giving me the suspicion that this was a line ending issue.
I then installed npm-watch in a local project, it failed with the same issue. After running the following one-liner to clobber the Windows line-endings:
sed 's/\r$//' -i node_modules/npm-watch/cli.js
It worked fine again. This puzzled me because all I saw in the git history was the removal of that console.log().
I did a little research, and this is an open issue with npm and cross-platform compatibility: https://github.com/npm/npm/issues/2097
So if you published from a Windows machine, npm publish sends the \r\n, but then git commit is converting the line endings and commiting \n, so you never see it in the repo.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (8 by maintainers)

Top Related StackOverflow Question
I agree, it would be nice if npm’s ‘publish’ command just took care of it in a cross-platform way. But! I have an idea.
There is a module called crlf that will convert
\r\nto\nI just smoke-tested it and it appears to work fine.
If you create a
prepublishlifecycle script and use it in there, that should take care of it before every time you publish.Or do it manually.
Or something else similar that uses that
prepublishhook.Thank you both for the help in diagnosing