purescript/npm-installer

purs --version raise error , probably installation issue

shishini opened this issue · 11 comments

When I run purs --version I get an error

PS C:\dev\lang\purescript\project\purescript-book\exercises\chapter2> purs --version
ResourceUnavailable: C:\Users\ammsel\AppData\Roaming\npm\purs.ps1:10
Line |
  10 |  & "$basedir/node_modules/purescript/purs.bin"   $args
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Program 'purs.bin' failed to run: No application is associated with the specified file for this operation.At C:\Users\ammsel\AppData\Roaming\npm\purs.ps1:10 char:1 + &
     | "$basedir/node_modules/purescript/purs.bin"   $args + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.

This is how I installed purescript

PS C:\dev\lang\purescript\project\purescript-book\exercises\chapter2> npm install -g purescript
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142

added 152 packages, and audited 153 packages in 14s

6 packages are looking for funding
  run `npm fund` for details

Note that commands such as spago test and spago repl seem to run fine

PS C:\dev\lang\purescript\project\purescript-book\exercises\chapter2> spago repl
PSCi, version 0.13.8
Type :? for help

>

Also note I am running windows 10

Installing via npm doesn’t normally create a purs.ps1 file, as far as I’m aware, so that might be what’s causing it to get tripped up. Can you let me know what version of npm you’re using and can you also show us the contents of that file please?

garyb commented

I think it might if you're using npm in powershell, similar to the way it creates a batch file when using cmd.

garyb commented

Here's some more info on this issue actually: https://discourse.purescript.org/t/why-not-purs-exe-instead-of-purs-bin/1737

Seems to be to do with the local configuration.

I was using powershell version 7.1.0 and npm version 7.3.0

And for the record, it is in my path

PS C:\Users\ammsel> get-command purs

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
ExternalScript  purs.ps1                                                      C:\Users\ammsel\AppData\Roaming\npm\purs.ps1

PS C:\Users\ammsel> ($env:Path).Split(";") | Select-String -pattern "npm"

C:\Users\ammsel\AppData\Roaming\npm

PS C:\Users\ammsel>

Some more details
So it seems that powershell calls purs.ps1 which does not work
but the old command prompt calls purs.cmd which work

If I explicitly call purs.cmd from command shell it works

PS C:\Users\ammsel> purs.bin --version
purs.bin: The term 'purs.bin' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS C:\Users\ammsel> purs.ps1 --version
ResourceUnavailable: C:\Users\ammsel\AppData\Roaming\npm\purs.ps1:10
Line |
  10 |  & "$basedir/node_modules/purescript/purs.bin"   $args
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Program 'purs.bin' failed to run: No application is associated with the specified file for this operation.At C:\Users\ammsel\AppData\Roaming\npm\purs.ps1:10 char:1 + &
     | "$basedir/node_modules/purescript/purs.bin"   $args + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.

PS C:\Users\ammsel> purs.cmd --version
0.13.8
PS C:\Users\ammsel>
garyb commented

Does the solution in the linked discourse thread work? This in particular: https://discourse.purescript.org/t/why-not-purs-exe-instead-of-purs-bin/1737/13

I wonder if we should consider renaming it to purs.exe. As far as I know, Windows is the only OS with hangups about what executables can be called; I don't think having it be called purs.exe will cause any harm on other OSes, apart from potentially people thinking they've been shipped the wrong executable.

I kinda fixed it
I made a copy of purs.bin renamed it to purs.exe
and edited purs.ps1 to point to purs.exe

and now both purs.cmd and purs.exe work in their respective environments

I did not try the solution in the discourse forum

garyb commented

I wonder if we should consider renaming it to purs.exe. As far as I know, Windows is the only OS with hangups about what executables can be called; I don't think having it be called purs.exe will cause any harm on other OSes, apart from potentially people thinking they've been shipped the wrong executable.

Yeah, agreed - just figured we should be 100% sure that this is being caused by the same thing. From what @shishini has done to fix it locally, sounds like it is indeed. Thanks!

Just a reminder that this issue still exist, and when i updated purescript to version 0.14.2 (from 0.13.8),
i had to redo the manual fix

in C:\Users\<username>\AppData\Roaming\npm\node_modules\purescript
i made a copy of purs.bin and renamed it (the copy) to purs.exe

and i edited C:\Users\<username>\AppData\Roaming\npm\purs.ps1
s/purs.bin/purs.exe/
i replaced purs.bin with purs.exe