question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line endings break cli.js on Unix Machines

See original GitHub issue

After 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:closed
  • Created 7 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jcpstcommented, Mar 31, 2016

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\n to \n

I just smoke-tested it and it appears to work fine.

If you create a prepublish lifecycle script and use it in there, that should take care of it before every time you publish.

{
  "scripts": {
    "prepublish": "crlf --set=LF cli.js"
  }
}

Or do it manually.

Or something else similar that uses that prepublish hook.

0reactions
M-Zubercommented, Apr 2, 2016

Thank you both for the help in diagnosing

Read more comments on GitHub >

github_iconTop Results From Across the Web

Line endings in Javascript - SitePoint
As you may know, the humble line break actually has three forms depending on which operating system is doing the breaking. On Unix...
Read more >
bin scripts should always have Unix line endings · Issue #12371
Just add "prepublish": "dos2unix index.js" line to your "scripts" in package.json. Also make sure that dos2unix is added to the dev dependencies ...
Read more >
bash - Are shell scripts sensitive to encoding and line endings?
Yes. Bash scripts are sensitive to line-endings, both in the script itself and in data it processes. They should have Unix-style line-endings, i.e., ......
Read more >
DOS vs. Unix Line Endings
Text files created on DOS/Windows machines have different line endings than files created on Unix/Linux. DOS uses carriage return and line feed ("\r\n")...
Read more >
Line Breaks: From Windows to Unix and Back - CodeProject
UnixLineEndings accepts a string that contains any combination of line endings, returning a string in which every legitimate line ending is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found