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

Line endings of npm bash scripts is CRLF instead of LF in the Windows installation of node - /usr/bin/env: ‘bash\r’: No such file or directory #43860

Closed
hrishikesh-kadam opened this issue Jul 16, 2022 · 4 comments · Fixed by #43879
Labels
windows Issues and PRs related to the Windows platform.

Comments

@hrishikesh-kadam
Copy link
Contributor

hrishikesh-kadam commented Jul 16, 2022

What is the problem this feature will solve?

Line endings of the npm and other bash scripts are CRLF (\r\n) instead of LF (\n) in the Windows installation of the node.

Git Bash
hrkad@HRK-HPZBOOK MINGW64 /c/Program Files/nodejs
$ \ls -alFh
total 62M
drwxr----- 1 hrkad 197610    0 Jul 16 19:50 ./
drwxr----- 1 hrkad 197610    0 Jul 16 16:46 ../
-rwxr----- 1 hrkad 197610  334 Jul  8 06:00 corepack*
-rw-r----- 1 hrkad 197610  218 Jul  8 06:00 corepack.cmd
-rw-r----- 1 hrkad 197610 3.0K Jul  8 06:00 install_tools.bat
-rwxr----- 1 hrkad 197610  62M Jul 13 14:32 node.exe*
-rw-r----- 1 hrkad 197610 8.8K Oct 14  2021 node_etw_provider.man
drwxr----- 1 hrkad 197610    0 Jul 16 16:34 node_modules/
-rw-r----- 1 hrkad 197610  702 Oct 14  2021 nodevars.bat
-rwxr----- 1 hrkad 197610 1.4K Jul 16 19:50 npm*
-rw-r----- 1 hrkad 197610  483 Jul  7 06:00 npm.cmd
-rwxr----- 1 hrkad 197610 1.6K Jul  7 06:00 npx*
-rw-r----- 1 hrkad 197610  539 Jul  7 06:00 npx.cmd

hrkad@HRK-HPZBOOK MINGW64 /c/Program Files/nodejs
$ cat -v npm | head -1
#!/usr/bin/env bash^M

hrkad@HRK-HPZBOOK MINGW64 /c/Program Files/nodejs
$ cat -v npx | head -1
#!/usr/bin/env bash^M

hrkad@HRK-HPZBOOK MINGW64 /c/Program Files/nodejs
$ cat -v corepack | head -1
#!/bin/sh^M

This causes npm scripts unable to use on WSL distros like Ubuntu.

WSL Ubuntu 22.04 LTS
hrk@HRK-HPZBOOK:.../Program Files/nodejs$ pwd
/mnt/c/Program Files/nodejs

hrk@HRK-HPZBOOK:.../Program Files/nodejs$ npm --version
/usr/bin/env: ‘bash\r’: No such file or directory

hrk@HRK-HPZBOOK:.../Program Files/nodejs$ npx --version
/usr/bin/env: ‘bash\r’: No such file or directory

hrk@HRK-HPZBOOK:.../Program Files/nodejs$ corepack --version
-bash: /mnt/c/Program Files/nodejs/corepack: /bin/sh^M: bad interpreter: No such file or directory

On Git Bash, the npm scripts with CRLF endings are interpreted without an issue.

Git Bash
hrkad@HRK-HPZBOOK MINGW64 /c/Program Files/nodejs
$ npm --version
8.14.0

hrkad@HRK-HPZBOOK MINGW64 /c/Program Files/nodejs
$ npx --version
8.14.0

hrkad@HRK-HPZBOOK MINGW64 /c/Program Files/nodejs
$ corepack --version
0.12.0

What is the feature you are proposing to solve the problem?

Line endings of the npm and other bash scripts should be LF (\n) instead of CRLF (\r\n) in the Windows installation of the node.

What alternatives have you considered?

Using dos2unix.exe from Git Bash solves the issue.

Git Bash
hrkad@HRK-HPZBOOK MINGW64 /c/Program Files/nodejs
$ dos2unix.exe npm
dos2unix: converting file npm to Unix format...

hrkad@HRK-HPZBOOK MINGW64 /c/Program Files/nodejs
$ dos2unix.exe npx
dos2unix: converting file npx to Unix format...

hrkad@HRK-HPZBOOK MINGW64 /c/Program Files/nodejs
$ dos2unix.exe corepack
dos2unix: converting file corepack to Unix format...
WSL Ubuntu 22.04 LTS
hrk@HRK-HPZBOOK:.../Program Files/nodejs$ npm --version
8.14.0

hrk@HRK-HPZBOOK:.../Program Files/nodejs$ npx --version
8.14.0

hrk@HRK-HPZBOOK:.../Program Files/nodejs$ corepack --version
/mnt/c/Program Files/nodejs/corepack: 11: exec: node: not found

Although, corepack --version in the above session fails due to another issue of missing node shim script pointing to node.exe

Other alternatives to installing node natively on WSL obviously solve the issue but it causes double dependencies of the core software and global packages, one on Windows and the other inside WSL.

@hrishikesh-kadam hrishikesh-kadam added the feature request Issues that request new features to be added to Node.js. label Jul 16, 2022
@aduh95 aduh95 added windows Issues and PRs related to the Windows platform. and removed feature request Issues that request new features to be added to Node.js. labels Jul 16, 2022
@aduh95
Copy link
Contributor

aduh95 commented Jul 16, 2022

How did you install Node.js?

@hrishikesh-kadam
Copy link
Contributor Author

@aduh95 Using https://nodejs.org/dist/v18.6.0/node-v18.6.0-x64.msi as well as winget install OpenJS.NodeJS

@aduh95
Copy link
Contributor

aduh95 commented Jul 17, 2022

/cc @nodejs/platform-windows

@hrishikesh-kadam
Copy link
Contributor Author

@aduh95 I have found the issue.
Working on it locally.
I would like to have my first node contribution commit for this.
Please give me a day or 2.

hrishikesh-kadam added a commit to hrishikesh-kadam/node that referenced this issue Jul 17, 2022
This issue has been described in -
nodejs#43860

On Windows system, git clone or git checkout on the repo turns LF line
endings to CRLF in the worktree.
This can happen due to many reasons like -
- git config --system core.autocrlf (set to true)
- git config --global core.autocrlf (set to true)
- git config --local core.autocrlf (set to true)
- git clone --config core.autocrlf=true ...

Adding gitattributes for the shims will not convert them to CRLF line
endings.

Also, there is a note[1] in test/README.md which says -
For the tests to run on Windows, be sure to clone Node.js source code
with the `autocrlf` git config flag set to true.

Reason for using build subsystem -
These shims are just copied in stage_package label of vcbuild.bat

Fixes: nodejs#43860
[1]: nodejs@3654cd4
nodejs-github-bot pushed a commit that referenced this issue Jul 19, 2022
This issue has been described in -
#43860

On Windows system, git clone or git checkout on the repo turns LF line
endings to CRLF in the worktree.
This can happen due to many reasons like -
- git config --system core.autocrlf (set to true)
- git config --global core.autocrlf (set to true)
- git config --local core.autocrlf (set to true)
- git clone --config core.autocrlf=true ...

Adding gitattributes for the shims will not convert them to CRLF line
endings.

Also, there is a note[1] in test/README.md which says -
For the tests to run on Windows, be sure to clone Node.js source code
with the `autocrlf` git config flag set to true.

Reason for using build subsystem -
These shims are just copied in stage_package label of vcbuild.bat

Fixes: #43860
[1]: 3654cd4

PR-URL: #43879
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
danielleadams pushed a commit that referenced this issue Jul 26, 2022
This issue has been described in -
#43860

On Windows system, git clone or git checkout on the repo turns LF line
endings to CRLF in the worktree.
This can happen due to many reasons like -
- git config --system core.autocrlf (set to true)
- git config --global core.autocrlf (set to true)
- git config --local core.autocrlf (set to true)
- git clone --config core.autocrlf=true ...

Adding gitattributes for the shims will not convert them to CRLF line
endings.

Also, there is a note[1] in test/README.md which says -
For the tests to run on Windows, be sure to clone Node.js source code
with the `autocrlf` git config flag set to true.

Reason for using build subsystem -
These shims are just copied in stage_package label of vcbuild.bat

Fixes: #43860
[1]: 3654cd4

PR-URL: #43879
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this issue Jul 31, 2022
This issue has been described in -
#43860

On Windows system, git clone or git checkout on the repo turns LF line
endings to CRLF in the worktree.
This can happen due to many reasons like -
- git config --system core.autocrlf (set to true)
- git config --global core.autocrlf (set to true)
- git config --local core.autocrlf (set to true)
- git clone --config core.autocrlf=true ...

Adding gitattributes for the shims will not convert them to CRLF line
endings.

Also, there is a note[1] in test/README.md which says -
For the tests to run on Windows, be sure to clone Node.js source code
with the `autocrlf` git config flag set to true.

Reason for using build subsystem -
These shims are just copied in stage_package label of vcbuild.bat

Fixes: #43860
[1]: 3654cd4

PR-URL: #43879
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this issue Jul 31, 2022
This issue has been described in -
#43860

On Windows system, git clone or git checkout on the repo turns LF line
endings to CRLF in the worktree.
This can happen due to many reasons like -
- git config --system core.autocrlf (set to true)
- git config --global core.autocrlf (set to true)
- git config --local core.autocrlf (set to true)
- git clone --config core.autocrlf=true ...

Adding gitattributes for the shims will not convert them to CRLF line
endings.

Also, there is a note[1] in test/README.md which says -
For the tests to run on Windows, be sure to clone Node.js source code
with the `autocrlf` git config flag set to true.

Reason for using build subsystem -
These shims are just copied in stage_package label of vcbuild.bat

Fixes: #43860
[1]: 3654cd4

PR-URL: #43879
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this issue Aug 1, 2022
This issue has been described in -
#43860

On Windows system, git clone or git checkout on the repo turns LF line
endings to CRLF in the worktree.
This can happen due to many reasons like -
- git config --system core.autocrlf (set to true)
- git config --global core.autocrlf (set to true)
- git config --local core.autocrlf (set to true)
- git clone --config core.autocrlf=true ...

Adding gitattributes for the shims will not convert them to CRLF line
endings.

Also, there is a note[1] in test/README.md which says -
For the tests to run on Windows, be sure to clone Node.js source code
with the `autocrlf` git config flag set to true.

Reason for using build subsystem -
These shims are just copied in stage_package label of vcbuild.bat

Fixes: #43860
[1]: 3654cd4

PR-URL: #43879
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Fyko pushed a commit to Fyko/node that referenced this issue Sep 15, 2022
This issue has been described in -
nodejs#43860

On Windows system, git clone or git checkout on the repo turns LF line
endings to CRLF in the worktree.
This can happen due to many reasons like -
- git config --system core.autocrlf (set to true)
- git config --global core.autocrlf (set to true)
- git config --local core.autocrlf (set to true)
- git clone --config core.autocrlf=true ...

Adding gitattributes for the shims will not convert them to CRLF line
endings.

Also, there is a note[1] in test/README.md which says -
For the tests to run on Windows, be sure to clone Node.js source code
with the `autocrlf` git config flag set to true.

Reason for using build subsystem -
These shims are just copied in stage_package label of vcbuild.bat

Fixes: nodejs#43860
[1]: nodejs@3654cd4

PR-URL: nodejs#43879
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
guangwong pushed a commit to noslate-project/node that referenced this issue Oct 10, 2022
This issue has been described in -
nodejs/node#43860

On Windows system, git clone or git checkout on the repo turns LF line
endings to CRLF in the worktree.
This can happen due to many reasons like -
- git config --system core.autocrlf (set to true)
- git config --global core.autocrlf (set to true)
- git config --local core.autocrlf (set to true)
- git clone --config core.autocrlf=true ...

Adding gitattributes for the shims will not convert them to CRLF line
endings.

Also, there is a note[1] in test/README.md which says -
For the tests to run on Windows, be sure to clone Node.js source code
with the `autocrlf` git config flag set to true.

Reason for using build subsystem -
These shims are just copied in stage_package label of vcbuild.bat

Fixes: nodejs/node#43860
[1]: nodejs/node@3654cd4

PR-URL: nodejs/node#43879
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants