yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.43k stars 2.72k forks source link

Wrong line endings after installation #5480

Open noldor opened 6 years ago

noldor commented 6 years ago

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.

rally25rs commented 6 years ago

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.

noldor commented 6 years ago

So behaviour should be same with npm?

rally25rs commented 6 years ago

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.

grigio commented 6 years ago

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 commented 6 years ago

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

renttek commented 6 years ago

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

drkvogel commented 6 years ago

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.

Remolten commented 5 years ago

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

roman-sitewits commented 3 years ago

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.

vagusX commented 3 years ago

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

rally25rs commented 3 years ago

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

vagusX commented 3 years ago

@rally25rs got it✔️

phortx commented 1 month ago

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