yarn icon indicating copy to clipboard operation
yarn copied to clipboard

Wrong line endings after installation

Open noldor opened this issue 7 years ago • 13 comments

What is the current behavior? After installing npm-scripts-info, all files of this package have CRLF line endings and it cause error:

/usr/bin/env: «node\r»: No such file or directory

If the current behavior is a bug, please provide the steps to reproduce.

yarn add --dev npm-scripts-info
./node_modules/.bin/npm-scripts-info

What is the expected behavior? Expected to have no errors while running script. If install package through npm, it works correct.

Please mention your node.js, yarn and operating system version.

  • Node 9.70
  • Ubuntu 17.10
  • Yarn 1.5.1

noldor avatar Mar 07 '18 21:03 noldor

wow... so npm actually changes the line endings for files listed in package.json "bins". 😞

The npm-scripts-info package ships with CRLF line endings on all their files. npm changes the one file listed in bins which in this case is lib/cli.js:

~/Projects/npm-test 🐒   file node_modules/npm-scripts-info/lib/cli.js
node_modules/npm-scripts-info/lib/cli.js: a /usr/bin/env node script text executable, ASCII text

~/Projects/npm-test 🐒   file node_modules/npm-scripts-info/lib/index.js
node_modules/npm-scripts-info/lib/index.js: ASCII text, with CRLF line terminators

~/Projects/npm-test 🐒   file node_modules/npm-scripts-info/lib/default-info.js
node_modules/npm-scripts-info/lib/default-info.js: ASCII text, with CRLF line terminators

It's unfortunate that npm edits packages and tries to "correct" them instead of encouraging package owners to publish valid packages. But I guess the precedent has been set.

Thanks for reporting this. I'll flag this as a compatibility bug. If you want to work up a PR, we would appreciate it.

edit:

I also checked this on Windows and it looks like npm does not change the line endings for that file. So npm must be converting it to the "normal" line endings for the current OS.

rally25rs avatar Mar 09 '18 02:03 rally25rs

So behaviour should be same with npm?

noldor avatar Mar 09 '18 17:03 noldor

I would expect the behavior to be the same in npm and yarn. In this case it makes sense for yarn to change to match npm.

rally25rs avatar Mar 09 '18 23:03 rally25rs

I confirm this bug with Ubuntu 17.10 / node v9.11.1 / yarn 1.6.0. I don't have this bug with npm

grigio avatar Apr 18 '18 22:04 grigio

as workaround it worked for me dos2unix -F node_modules/.bin/soltsice (it was the file with CRLF)

grigio avatar Apr 18 '18 22:04 grigio

Same problem (Ubuntu 18.04, yarn 1.9.4). This issue was opened aboutr 6 months ago; is there any progress?

renttek avatar Sep 20 '18 08:09 renttek

Just encountered this with json-mock-server on macos. Bin scripts in that package have crlf endings. When installed and run with npm they work, but when the package is installed with yarn and run either by npm run or yarn run, I get the \r error.

drkvogel avatar Oct 12 '18 18:10 drkvogel

I fixed it with dos2unix -F node_modules/.bin/*.

Remolten avatar Feb 19 '19 03:02 Remolten

I'm guessing the long-term fix for this is to move away from Windows for development. In the meanwhile we can make sure to add the .editorconfig file in the root, or simply switch the encoding in your VSCode project to generate that file.

It can be something like this:

# All files.
[*]
end_of_line = LF
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

Also can be set in GIT > git config --global core.autocrlf false. But make sure your files in Windows are still only save LF in files, as in .editorconfig above, or git status will complain.

roman-sitewits avatar Apr 19 '21 22:04 roman-sitewits

@rally25rs I'm trying to write a pr to fix this issue~

vagusX avatar Oct 14 '21 14:10 vagusX

Note that yarn v1 is no longer under development, other than critical and security fixes. A PR may sit open indefinitely. Everyone is encouraged to look into migrating to yarn v2

⁣Sent from TypeApp ​

On Oct 14, 2021, 10:49 AM, at 10:49 AM, vagusX @.> wrote: @. I'm trying to write a pr to fix this issue~

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/yarnpkg/yarn/issues/5480#issuecomment-943432971

rally25rs avatar Oct 14 '21 15:10 rally25rs

@rally25rs got it✔️

vagusX avatar Oct 14 '21 15:10 vagusX

I had this bug today with vitepress-export-pdf package, see details here: https://github.com/condorheroblog/vitepress-export-pdf/issues/24

phortx avatar Aug 29 '24 10:08 phortx