-
Notifications
You must be signed in to change notification settings - Fork 3k
npm publish from Windows handles CRLF incorrectly #2097
Comments
+1 for this issue, something similar to git's core.autocrlf option needs to be implemented. |
+1 Hopefully this can be addressed soon. |
Oh eww, I didn't know I was doing this to people :( |
Hm, yeah, that's a pita. It'd be nice for npm to do this automatically when generating the tarball, but I'm not sure how without potentially breaking binary files. There's got to be some kind of way to detect if it's a "text" file, right? Git has this, after all. |
+1 Oh it can just be reached easy by implement a function to figure out the first line of the binary which defined in the "bin" field of package.json that starts with |
@heycalmdown Well, ideally npm should convert \r\n to \n in ALL non-binary files when creating the tarball on Windows. |
@isaacs maybe ideally it should warn and exit, but optionally with eg |
From an implementation point of view: Ideally the change should not impact the files on disk. It probably needs to happen as part of the packing that goes into As I understand it, https://github.com/isaacs/fstream-npm just emits file name events that What if |
I have a work-around for this issue that has been verified to work. @isaacs, I want to point out that no, it's not a good idea to replace all non-binary file line endings with |
+1 I've hit this one several times. Tonight it got nastier as I'd publish a lib containing a package.json file that had CRLF's in it (unknown to me). I then attempted to publish another dependent package but npm refused to publish it because the lib it depended on contained an unparsable package.json. Really ugly stuff! Cleaning up CRLFs would prevent this. I now tend to run dos2unix on most of my files prior to publishing just to be sure. This is really getting painful. |
I think you could make it either an npm command line option or perhaps in package.json define a list of file patterns to convert (or not convert). |
My solution has been to do all of my development with LF and ban CRLF files from my source code folder. |
Yes I've done the same - but still hitting issues. Enforced with .gitattribute files also. However I use several IDEs/Editors and I think one of them is to blame. |
But getting npm to help would prevent most of these problems. |
Thanks! |
+1 I just ran in to this...turns out Github for Windows is overriding my git line ending preferences and applying CRLF in all my clones. Worse still Github for Windows doesn't let you choose your line ending preferences so forced back to cloning from the console :'( |
@pflannery actually it does let you choose. Just go into the repository in question and run the following:
The first command tells Git to never change line endings (in the future). Next, we refresh each repository by removing every file from Git's index and, finally, rewriting the Git index to pick up all the new line endings. This fixes the CRLFs that were introduced to your local file system when you cloned each repository. |
I tried this and didn't get anywhere. I also tried it from a linux system and was unable to remove the CRLFs from the remote. I don't disagree that git can do this, just not without giving me a hernia. |
@jedmao but when I |
@jedmao looking deeper it seems github uses portable-git and not the git I installed from git-scm.com....I'll try to set the config for portable-git.. |
Yes, it's important to know that you are using the same Git everywhere. In my experience, the only Git I install is GitHub for Windows. Then, I track down the msysgit installation path by navigating to |
And @pflannery, remember to use the Git Shell. The GitHub for Windows installation should have created a shortcut for you. You can also open a shell from the UI's gear icon. |
Closing this in favor of #12371, which I believe preserves the simplest way to resolve this, as well as a path for those who might be up to sending us a solution before we have the time to do so ourselves. Thanks to all for their time and (especially) patience. |
When published from a Windows machine, the package files are uploaded with the windows-style CRLF endings. This is fine for most files, but if there are any shell scripts or a specified bin file, then those files will be corrupt and fail on a Linux machine.
I encountered this behavior publishing some of my packages from Windows from a git repository, using e.g.
I understand why this occurs, but since this makes
npm publish
50% unusable on Windows, I think it is fair to call it a bug in npm.The text was updated successfully, but these errors were encountered: