1

I have this issue, and whenever I do npm init the file package.json is created, but it is formatted in one line. As you can imagine this is not practical to work with and I end up formatting it myself, which is not the best task in the world.

EDIT
I have noticed that when I do npm install the file gets reformatted again to one line. This is very annoying and I'm sure it must be some configuration that I cannot find.

What should I change to have the file formatted from the beginning?

Thanks!

Daniel Reina
  • 5,764
  • 1
  • 37
  • 50
  • Could you please tell something about your OS and IDE setup? Are you running on Windows and probably using an editor that doesn't handle unix line endings correctly? – Andreas Jägle Aug 16 '16 at 21:51
  • That's correct, my OS is Windows 7, and I'm trying to see the file with the notepad. Now that you've asked about unix line endings, I've opened it with Sublime Text 3 and everything is perfectly formatted...So the answer would be "burn notepad", right? – Daniel Reina Aug 16 '16 at 21:57
  • Yes, you should use some more advanced editor that can at least handle all kinds of line endings and detect encodings. – Andreas Jägle Aug 16 '16 at 22:00
  • Great! Thank you very much for your help. I can't believe I didn't try to open the file with sublime until I read your comment... If you want to write it as the answer, I will give accept it. Thank you again :) – Daniel Reina Aug 16 '16 at 22:02

1 Answers1

2

When npm creates and updates the files, it rewrites the line endings to unix-style LF whereas windows endings are CRLF. When using an editor that doesn't handle unix endings correctly, you will see the whole content in one line.

So: use an editor that can handle unix line endings correctly.

Andreas Jägle
  • 11,632
  • 3
  • 31
  • 31
  • Rewriting `CRLF` to `LF` on updates was indeed a [bug](https://github.com/npm/npm/issues/17161) which is fixed now. However, using `LF` on `git init` works as [designed](https://github.com/npm/npm/issues/1767). – Darek Kay Jun 12 '18 at 10:30