Windows 7
Yarn 1.3.2 (the same issue with 1.1.0)
Git 2.16.1.windows.4
The path to Yarn is in the Environment PATH variable: D:\Program Files (x86)\Yarn\bin
Yarn works in Windows cmd.exe and PowerShell console. For example:
c:>yarn --version
But does not work in Git Bash:
$ yarn --version
module.js:538
throw err;
^
Error: Cannot find module 'C:\Program Files\Git\yarn.js'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
I restarted Windows after yarn installation.
What is the output of which yarn
in Git Bash?
/d/Program Files (x86)/Yarn/bin/yarn
Just found that yarn.cmd command works.
For example:
$ yarn.cmd --version
1.3.2
But:
$ yarn --version
module.js:538
throw err;
^
Error: Cannot find module 'C:\Program Files\Git\yarn.js'
And, what is the output of which yarn.cmd
?
$ which yarn.cmd
which: no yarn.cmd in (/c/Users/USERNAME_HERE/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/USERNAME_HERE/bin:/d/Program Files/Python35/Scripts:/d/Program Files/Python35:/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/lib/x64:
... (lots of paths here) ...
/d/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin:/d/Caffe/python:/cmd:/d/Program Files (x86)/Yarn/bin:/c/Users/USERNAME_HERE/AppData/Local/Yarn/bin:/c/Users/USERNAME_HERE/AppData/Roaming/npm:/c/Users/USERNAME_HERE/AppData/Local/Yarn/bin:/usr/bin/vendor_perl:/usr/bin/core_perl)
This doesn't seem like a problem with Yarn. Try adding it to PATH
in ~/.bash_profile
.
Well, other things like _npm_ and _nodejs_ work fine. Only _yarn_ does not.
I added the path to yarn to PATH to the profile this way:
PATH=$PATH':/d/Program Files (x86)/Yarn/bin'
The error message is still the same.
The same problem has occurred in msys2. I run msys2 on Windows 8.1.
$ yarn
module.js:559
throw err;
^
Error: Cannot find module 'C:\yarn.js'
at Function.Module._resolveFilename (module.js:557:15)
at Function.Module._load (module.js:484:25)
at Function.Module.runMain (module.js:703:10)
at startup (bootstrap_node.js:193:16)
at bootstrap_node.js:665:3
I edited the yarn script and confirmed it.
It seems to be caused by the result of sed becoming empty character.
$ cat /c/Program\ Files\ \(x86\)/Yarn/bin/yarn
#!/bin/sh
echo "0: $0"
argv0=$(echo "$0" | sed -e 's,\\,/,g')
echo "argv0: $argv0"
basedir=$(dirname "$(readlink "$0" || echo "$argv0")")
echo "basedir: $basedir"
...
[result]
$ yarn
0: /c/Program Files (x86)/Yarn/bin/yarn
argv0:
basedir: .
md5-7186f67fe0e2d4d229da401048a9c212
$ cat /c/Program\ Files\ \(x86\)/Yarn/bin/yarn
#!/bin/zsh
...
md5-f990ce151bfffd2d1425b4c1a7de6bb8
$ yarn --version
1.3.2
The cause was found out. This is caused by MacType.
https://sourceforge.net/p/msys2/discussion/general/thread/aa858e3e/
Please uninstall MacType and try it.
I do not have MacType on my PC. So, in my case Yarn issue is not related to MacType.
Same issues replicated on a freshly installed Windows 10 Pro 64-bit machine:
Git for windows 2.16.2-64-bit (Also tried with 2.15.x)
NVM for Windows 1.1.6 (Also tried with 1.1.5)
Yarn 1.5.1 (Also tried with 1.3.2)
When run from cmd.exe:
C:\Users\echristensen>yarn --version
1.5.1
When run from Powershell:
PS C:\Users\echristensen> yarn --version
1.5.1
When run from Git Bash (MINGW64):
echristensen@ECHRISTENSEN-PC MINGW64 ~
$ yarn --version
module.js:478
throw err;
^
Error: Cannot find module 'C:\Users\echristensen\yarn.js'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:387:7)
at startup (bootstrap_node.js:153:9)
at bootstrap_node.js:500:3
The funny thing is that it works if I run the js file directly or the cmd from Git Bash:
echristensen@ECHRISTENSEN-PC MINGW64 ~
$ yarn.js --version
1.5.1
echristensen@ECHRISTENSEN-PC MINGW64 ~
$ yarn.cmd --version
1.5.1
Bonus information:
Git for Windows:
echristensen@ECHRISTENSEN-PC MINGW64 ~
$ which yarn
/c/Program Files (x86)/Yarn/bin/yarn
echristensen@ECHRISTENSEN-PC MINGW64 ~
$ which yarn.js
/c/Program Files (x86)/Yarn/bin/yarn.js
echristensen@ECHRISTENSEN-PC MINGW64 ~
$ which yarn.cmd
which: no yarn.cmd in (/c/Users/echristensen/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/echristensen/bin:/c/Python27:/c/Python27/Scripts:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/Program Files/dotnet:/c/Program Files/Microsoft SQL Server/130/Tools/Binn:/cmd:/c/Program Files (x86)/Yarn/bin:%NVM_HOME%:%NVM_SYMLINK%:/c/Users/echristensen/AppData/Local/Microsoft/WindowsApps:/c/Users/echristensen/AppData/Local/Yarn/bin:/c/Users/echristensen/AppData/Roaming/npm:/c/Users/echristensen/AppData/Roaming/nvm:/c/Program Files/nodejs:/usr/bin/vendor_perl:/usr/bin/core_perl)
cmd.exe:
C:\Users\echristensen>where yarn
C:\Program Files (x86)\Yarn\bin\yarn
C:\Program Files (x86)\Yarn\bin\yarn.cmd
C:\Program Files (x86)\Yarn\bin\yarn.js
I have the very same issue here on Windows 10 Pro. It happened when Windows rebooted after some update installation.
Looks like this is a git bash environment or config problem, the yarn
shell script could not set its basedir
path correctly (looks like it's empty) and so tries to execute node yarn.js
in current directory and of course there's no yarn.js to be found.
Not sure if this would be a separate Windows Git Bash path issue but it fits the title here:
Windows 7
yarn v1.6.0
git version 2.7.2.windows.1
$ yarn
module.js:538
throw err;
^
Error: Cannot find module 'C:\c\Program Files (x86)\Yarn\bin\yarn.js'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Resolved by adding MINGW64 to the yarn shell script basedir case statement:
case "$(uname -s)" in
Linux) basedir=$(dirname "$(readlink -f "$0" || echo "$argv0")");;
*CYGWIN* | *MINGW64*) basedir=`cygpath -w "$basedir"`;;
esac
Same kind of patch works if you are using MSYS on Windows 10:
case "$(uname -s)" in
Linux) basedir=$(dirname "$(readlink -f "$0" || echo "$argv0")");;
*CYGWIN* | *MSYS*) basedir=`cygpath -w "$basedir"`;;
esac
I am getting the following error when trying to use yarn from git bash:
$ yarn --version
module.js:538
throw err;
^
Error: Cannot find module 'C:cProgram Files (x86)Yarnbinyarn.js'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
I don't really know what i am doing, but i got a small and quick fix.
Edit C:Program Files (x86)Yarnbinyarn
Replace
basedir=$(dirname "$(readlink "$0" || echo "$argv0")")
by
basedir=$( cd -P -- "$(dirname -- "$0")" && pwd -P )
This works for me. I hope i can help some people out.
This might be a duplicate of https://github.com/git-for-windows/git/issues/1619. Is anyone here using Comodo Cloud Antivirus?
@dahlbyk Not a duplicate, I'm afraid, as I am not using Comodo and have the same problem (identical situation so far to @Yagun's posts), except:
Any other information I can provide to help debug?
@mordentware even if it's not specifically related to Comodo, this does seem like the same kind of problem. Are you able to reproduce these tests results: https://github.com/git-for-windows/git/issues/1619#issuecomment-394073051?
Fair comment. Created the shell script below (copying here for benefit of future people):
#!/bin/sh
echo "A) $0"
echo "B) $0" | sed -e 's,\\,/,g'
echo "C) $(echo "$0" | sed -e 's,\\,/,g')"
echo "D) $(dirname "$(echo "$0" | sed -e 's,\\,/,g')")"
echo $(ls) | cat
echo $(ls | cat)
echo $(echo $(ls) | cat)
Output in Git Bash:
$ ./test.sh
A) ./test.sh
B) ./test.sh
C)
D) .
Files...
Files...
Files...
My sed
-fu is weak, but I believe I should be expecting to see something in there? Based on the tweak to C:\Program Files (x86)\Yarn\bin\yarn
suggested by @Nielio above, that was able to fix my issue.
I'm not confident enough to say exactly what the cause of the issue is, but happy to report that (for 1.6.0, at least) this seems to be very relevant.
Looping in @dscho
This looks like (don't laugh, it is really sad) the old Comodo Internet Security problem. See https://github.com/git-for-windows/git/issues/1619 for the full story.
That was my thought, but @mordentware says he's not using Comodo. Not sure what else to try, or if there's anything here that's yarn-specific?
Yeah I'm not using Comodo Internet Security either. I am however using Sophos Antivirus. But I've had it working on the same PC with the same software installed before a reinstall. After the fresh install of Windows 10 Pro with pretty much nothing on it but Sophos Antivirus, I got this error.
@emilchristensen Is it possible you're using a different version of Node, which might be handled differently by Sophos? I don't suppose either of these products have any way of telling you when they so stuff that's affecting your runtime environment? 馃槖
I've tried with multiple versions of node, including the same version as I ran before the reinstall. And yeah, I don't see any logs anywhere for whether Sophos is affecting my runtime.
I have the exact same problem on Windows 7. Not using Comodo Internet Security.
@Nielio's workaround works for me.
Replace
basedir=$(dirname "$(readlink "$0" || echo "$argv0")")
by
basedir=$( cd -P -- "$(dirname -- "$0")" && pwd -P )
@Nielio interesting!
Note: you will want to imitate the coding style by avoiding the extra spaces after/before the parentheses, and you definitely will want to quote the result (the original code gets this wrong, too).
Does it also work for you if you instead edit the case
statement to catch *CYGWIN*|*MINGW*|*MSYS*
instead of only *CYGWIN*
? I think that would be the proper fix, and I guess that we will want to open a Pull Request in whatever project writes these shell scripts (it might be npm
?)
Does it also work for you if you instead edit the case statement to catch CYGWIN|MINGW|MSYS instead of only CYGWIN? I think that would be the proper fix, and I guess that we will want to open a Pull Request in whatever project writes these shell scripts (it might be npm?)
As can be seen here, I did exactly that.
@dscho It works! Even without changing the basedir line. Thank you!
This is my yarn file right now.
#!/bin/sh
argv0=$(echo "$0" | sed -e 's,\\,/,g')
basedir=$(dirname "$(readlink "$0" || echo "$argv0")")
case "$(uname -s)" in
Linux) basedir=$(dirname "$(readlink -f "$0" || echo "$argv0")");;
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac
command_exists() {
command -v "$1" >/dev/null 2>&1;
}
if command_exists node; then
if [ "$YARN_FORCE_WINPTY" = 1 ] || command_exists winpty && test -t 1; then
winpty node "$basedir/yarn.js" "$@"
else
exec node "$basedir/yarn.js" "$@"
fi
ret=$?
# Debian and Ubuntu use "nodejs" as the name of the binary, not "node", so we
# search for that too. See:
# https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=614907
elif command_exists nodejs; then
exec nodejs "$basedir/yarn.js" "$@"
ret=$?
else
>&2 echo 'Yarn requires Node.js 4.0 or higher to be installed.'
ret=1
fi
exit $ret
Great! Now, if only we could get that PR going... Not sure whether there is any maintainer at cmd-shim
...
New to all this, but also ran into this issue trying to use yarn in Git Bash 2.18.0 for Windows.
OS: Windows 10 Enterprise 64-bit
Git Bash: v2.18.0
Yarn: v1.0.2
I have a specific version of yarn installed in a custom location /c/yarn/yarn-v1.0.2/bin. Added this path in PATH environment variable. Was getting the same "Error: Cannot find module 'C:Program FilesGityarn.js'" error.
My workaround was to update the basedir line in the "yarn" file (under /c/yarn/yarn-v1.0.2/bin) as shown below.
basedir=$(dirname $(which yarn))
FYI, @dscho I appreciate your help and your posted solution. It obviously helped many here! I wasn't trying to report a bug to your solution, but I understand and appreciate your advice. I added more detail of my environment here. After editing the case statement to catch *CYGWIN*|*MINGW*|*MSYS*
instead of only *CYGWIN*
, I was still getting the same "Error: Cannot find module" error.
But thanks to all the comments here, I ended up changing the basedir line as shown above and that worked for me. Posting here in case it might help others. Thank you niello, dscho, and everyone here for posting your findings. This was really the only place I found with helpful information about this error when running yarn in git bash.
I tried @dscho solution and wasn't quite working.
A bug report like this is really frustrating to the developer who tried to help you. You might want to show your gratitude by improving the detail of your bug report a lot, to the point where it is actually useful in helping to figure out what needs to be improved. Right now, I know nothing, except that something is broken for you. Something. Really frustrating.
@Nielio fix worked for me, thank you
@GlenHughes @Nielio really, anybody in this community who is familiar with its inner workings, could you please help me get https://github.com/npm/cmd-shim/pull/30 accepted? Or are you happy with everybody and their friend having to work around this?
@dscho opened this for you: https://npm.community/t/fix-generated-shell-scripts-for-msys2-mingw/965
@dahlbyk thank you so much! Is this process documented anywhere (open PR on GitHub, new post on npm forum linking to the PR)?
No idea, just guessing since they disabled GH Issues on the CLI. 馃
Incase anyone is wondering about this issue, I've updated Git to 2.19.1 and its now working fine without having to apply @Nielio fix
@GlenHughes Updated what?
I updated Git. I've also updated my comment to be more clear.
@Nielio your fix worked for me, thank you 馃
@GlenHughes How did you update git in Windows Bash? I understand that this installation is different than the native one, correct?
@dscho opened this for you: https://npm.community/t/fix-generated-shell-scripts-for-msys2-mingw/965
@dahlbyk seems like nobody of those in power to review and merge the PR cared at all?
How did you update git in Windows Bash?
I think what we're talking about is the Git Bash included in Git for Windows. You upgrade it by installing a newer version of Git for Windows, as downloaded from https://gitforwindows.org/.
updating git for windows definitely fixed this problem for me.
I believe this is related to the same problem, yarn works OK when run from the Windows
side but not OK when run from the Bash
side (for the exaxt same project):
While in bash
, I get an error:
Note that git for windows
is different than the one in bash
:
@dscho I upgraded "Git for Windows"
I don't know how relevant is, but I'm experiencing some odd behavior, if I try to open a folder from within VSCode, yarn would not work at all. Though if I right click the same folder from the Windows Explorer and select open with VSCode, yarn would work perfectly fine.
I have a similar problem and @Nielio fix didn't help, it also happens in the windows command line!
yarn run v1.17.2
$ node scripts/start.js
/usr/bin/bash: Files\git\bin\bash.exe: No such file or directory
?[2K?[1G?[31merror?[39m Command failed with exit code 127.
?[2K?[1G?[94minfo?[39m Visit ?[1mhttps://yarnpkg.com/en/docs/cli/run?[22m for documentation about this command.
This is still an issue. I just upgraded to bash 4.4.23 and I still have problems. All yarn commands don't produce any output (there's just a somewhat large gap from when I start the command to my prompt, such as if I had run clear). Also, running yarn completely hides my prompt, which makes the shell basically unusable. I have to keep restarting my shell everytime I accidentally run yarn. Could you please add an option to disable winpty? It's super annoying.
Since yarn.cmd
works correctly as expected, the step below works for me without any stress.
Update your list of aliases in the .bash_profile file at C:\Users\yourUsername\.bash_profile
like so:
alias yarn='yarn.cmd'
Subsequently yarn can be used normally anywhere including from >_ git bash
.
It's caused by Trend Micro https://github.com/rprichard/winpty/issues/95 . I've tested now by installing Trend Micro Internet Security on a new fresh Microsoft Windows 2004 VM, and I experience this problem.
node --version
we have the same problem than with yarn --version
I encounter this problem also with MSYS2 3.1.7-340.x86_64 2020-08-27 11:03 UTC
and Cygwin 3.1.7(0.340/5/3) 2020-08-22 17:48
when I try to execute alias node="winpty node.exe" && node --version
.
We should probably make a PR to call directly node.exe
.
On npm
they do that https://github.com/npm/cli/blob/latest/bin/npm
See my PR #8355 . Note that with this PR, if there is a need of a REPL (like yarn add @angular/cli && yarn ng new test
), the REPL step is skipped. But as for npm
.
Note that on Bash windows when we type type node
it returns
node is aliased to `winpty node.exe'
In fact, it is defined as it into /etc/profile.d/aliases.sh
.
It seems that this here ticket is addressed, as of https://github.com/npm/cmd-shim/pull/30#event-2551131773.
@Yagun would you mind closing the ticket, please?
@YX-XiaoBai please note that this here bug tracker concerns itself about bugs in Git for Windows, not Git on macOS. I am not quite certain how the original report in this ticket is related to your report, but I am fairly certain that you are talking about a very different problem.
Most helpful comment
Same issues replicated on a freshly installed Windows 10 Pro 64-bit machine:
Git for windows 2.16.2-64-bit (Also tried with 2.15.x)
NVM for Windows 1.1.6 (Also tried with 1.1.5)
Yarn 1.5.1 (Also tried with 1.3.2)
When run from cmd.exe:
When run from Powershell:
When run from Git Bash (MINGW64):
The funny thing is that it works if I run the js file directly or the cmd from Git Bash: