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

Wrong line endings after installation #5480

Open
noldor opened this issue Mar 7, 2018 · 13 comments
Open

Wrong line endings after installation #5480

noldor opened this issue Mar 7, 2018 · 13 comments

Comments

@noldor
Copy link

noldor commented Mar 7, 2018

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
@rally25rs
Copy link
Contributor

rally25rs commented Mar 9, 2018

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
Copy link
Author

noldor commented Mar 9, 2018

So behaviour should be same with npm?

@rally25rs
Copy link
Contributor

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
Copy link

grigio commented Apr 18, 2018

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
Copy link

grigio commented Apr 18, 2018

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

@renttek
Copy link

renttek commented Sep 20, 2018

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

@drkvogel
Copy link

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.

rgladwell added a commit to rg-wood/scribe-cli that referenced this issue Dec 14, 2018
The installed executable was failing on Mac with the following error:

`env: node\r: No such file or directory`

Solution as detailed here is to release from a Unix-based OS:

yarnpkg/yarn#5480
@Remolten
Copy link

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

rg-wood added a commit to rg-wood/scribe-cli that referenced this issue May 22, 2019
The installed executable was failing on Mac with the following error:

`env: node\r: No such file or directory`

Solution as detailed here is to release from a Unix-based OS:

yarnpkg/yarn#5480
darekkay added a commit to darekkay/static-marks that referenced this issue Jun 1, 2019
- 🐛 Publish package with LF line endings for yarn (see [#5480](yarnpkg/yarn#5480)).
@roman-sitewits
Copy link

roman-sitewits commented Apr 19, 2021

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
Copy link

vagusX commented Oct 14, 2021

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

@rally25rs
Copy link
Contributor

rally25rs commented Oct 14, 2021 via email

@vagusX
Copy link

vagusX commented Oct 14, 2021

@rally25rs got it✔️

jrnewton added a commit to jrnewton/github-readme-to-html that referenced this issue Mar 28, 2022
Follow the suggestions in yarnpkg/yarn#5480

- establish .editorconfig setting to ensure LF is used by editor
- establish .gitattributes setting to ensure LF is used upon checkout

Convert existing files to LF via dos2unix.
@phortx
Copy link

phortx commented Aug 29, 2024

I had this bug today with vitepress-export-pdf package, see details here: condorheroblog/vitepress-export-pdf#24

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

No branches or pull requests

9 participants