peggyjs / peggy

Peggy: Parser generator for JavaScript
https://peggyjs.org/
MIT License
926 stars 65 forks source link

Failed to run "peggy" on windows, "-S.exe" is missing, what's this? #514

Closed fy0 closed 3 days ago

fy0 commented 5 months ago
> yarn global add peggy
> peggy
'-S' is not recognized as an internal or external command, operable program or batch file.

I searched peggy.cmd on my computer, i found it use "-S.exe" to load peggy whether "-S" exists or not:

@IF EXIST "%~dp0\-S.exe" (
  "%~dp0\-S.exe"  node --experimental-vm-modules --no-warnings "%~dp0\..\peggy\bin\peggy.js" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  -S  node --experimental-vm-modules --no-warnings "%~dp0\..\peggy\bin\peggy.js" %*
)

env:

> node -v
v20.9.0

Is this situation a bug? it can works if i removed -S of ELSE case.

hildjj commented 5 months ago

I haven't tried installing with yarn or on windows. Can you help us narrow this down by trying:

I don't have easy access to a Windows dev environment at the moment, so trying out some options will help a lot. Thanks!

hildjj commented 5 months ago

What version of yarn are you using? When I try yarn global add peggy on yarn@4.1.1, I get:

Usage Error: The 'yarn global' commands have been removed in 2.x - consider using 'yarn dlx' or a third-party plugin instead
fy0 commented 5 months ago

What version of yarn are you using? When I try yarn global add peggy on yarn@4.1.1, I get:

Usage Error: The 'yarn global' commands have been removed in 2.x - consider using 'yarn dlx' or a third-party plugin instead

Thx for reply, i use yarn 1.22. Now it's already not a problem for me.

I forked pigeon(one of golang's peg tool), then rewrote it to generate haxe code. Now i can use my pigeon version to generate js peg parser!

And seems yarn is not much better than npm since 2024(and 1.x is not maintained), maybe i should switch back to npm, or use pnpm to instead.

lhsantos commented 2 weeks ago

I am experiencing this issue, and I think it has nothing to do with yarn itself. I hadn't noticed it before because I normally use WSL, but when I had to test the system in the Windows host, I found this issue. Using an earlier version of peggy, such as 3.0.2 or 2.0.1 on Windows, or using the latest version on WSL (Ubuntu), both cases by running with yarn, does not cause any problems.

hildjj commented 2 weeks ago

@lhsantos does it work with npx peggy or npm install peggy -g?

lhsantos commented 2 weeks ago

For npx peggy --version with latest version installed locally, same error. After installing peggy globally, npm install -g peggy, then running in some non node directory, npx peggy --version, same error.

hildjj commented 2 weeks ago

npx peggy won't look for the global one. Try just peggy -version after npm install -g peggy.

hildjj commented 2 weeks ago

Note: I'm assuming that whatever yarn version you have isn't installing the same wrapper .bat file that npm does, and trying to see if that's actually true.

lhsantos commented 2 weeks ago

npx peggy won't look for the global one. Try just peggy -version after npm install -g peggy.

Just peggy does not find the command, and I did run npx peggy in a non-node project directory, so the only one it could find would be the global one...

lhsantos commented 2 weeks ago

npx peggy won't look for the global one. Try just peggy -version after npm install -g peggy.

Just peggy does not find the command, and I did run npx peggy in a non-node project directory, so the only one it could find would be the global one...

Ah, sorry, actually peggy --version does find the command, it just ends with the same error related to '-S.exe'

david-sharer commented 5 days ago

I tested the PR on my machine and it seems to work across git bash, cmd, and powershell. Used these:

But then it got a bit weird. I tested the prior commands as well, and they only seemed to work w/ npm under cmd. ... but going back to double check the older versions, they all work for me on npm now? and I don't see the @IF EXIST "%~dp0\-S.exe" mentioned in OP anymore, instead it is IF EXIST "%dp0%\node.exe" This is the case with 3.0.2, 4.0.0, 4.0.3, and the PR.

hildjj commented 5 days ago

I thought it was supposed to have been working on NPM for quite a while. On yarn, there is this bug:

https://github.com/yarnpkg/berry/issues/6305

that isn't marked fixed yet.

david-sharer commented 5 days ago

IIRC it broke with npm via git bash via VS Code.

But I looked closer at the old image and it looks like despite which reporting the correct location, the error it spat out references yarn.

So I guess some environment caching nonsense was at play?

hildjj commented 5 days ago

I continue to thing that this is a yarn bug. With a modern npm or pnpm, the correct command wrapper should be written.

Another way to solve this would be to document this case with "Yarn is broken. Do not use it to install peggy until bug 6305 is fixed."

hildjj commented 5 days ago

Yet another approach would be to land #555 but add a new bug to remove that code if yarn's 6305 is fixed. That seems like the best short-term approach.