Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line endings break cli.js on Unix Machines #15

Closed
jcpst opened this issue Mar 31, 2016 · 10 comments
Closed

Line endings break cli.js on Unix Machines #15

jcpst opened this issue Mar 31, 2016 · 10 comments

Comments

@jcpst
Copy link

jcpst commented Mar 31, 2016

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: npm/npm#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.

@M-Zuber
Copy link
Owner

M-Zuber commented Mar 31, 2016

So a little story: I HATE THIS LINE ENDING BUSINESS

Rant over, sorry about that.

I am mainly a windows guy, so correct me if I am wrong - Currently the only way to avoid this issue is by publishing from a linux machine?

@jcpst
Copy link
Author

jcpst commented 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.

@abritinthebay
Copy link
Contributor

In theory a .gitattributes file (plus maybe a commit that fixes the current issue) should keep it from ever happening again.

@abritinthebay
Copy link
Contributor

Note - right now you have text=auto you probably want text eol=lf otherwise it's going to tank on 2/3 platforms (and the most common node platforms)

@abritinthebay
Copy link
Contributor

You can also change most text editors to have Unix style (linefeed only) line endings like OSX and all Linux flavors use.

@M-Zuber M-Zuber closed this as completed in f7594d3 Apr 1, 2016
M-Zuber added a commit that referenced this issue Apr 1, 2016
updating gitattributes to prefer unix-style line endings (should fix #15)
@M-Zuber
Copy link
Owner

M-Zuber commented Apr 1, 2016

I merged the fix for the .gitattributes file, but I think I will still add the prepublish hook as I do not want to rely on npm honoring the file.

@M-Zuber
Copy link
Owner

M-Zuber commented Apr 1, 2016

ok, I've pushed v0.1.13.
@jcpst @abritinthebay if you could double check it for me when you get a chance and let me know if it worked

@jcpst
Copy link
Author

jcpst commented Apr 1, 2016

Works! Thank you @M-Zuber

@abritinthebay
Copy link
Contributor

Yup, works great now. the prepublish hook makes sense - can't hurt to make sure

@M-Zuber
Copy link
Owner

M-Zuber commented Apr 2, 2016

Thank you both for the help in diagnosing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants