haskellhaskell-stack

Haskell stack gives InvalidRelDir error no matter the input


I am encountering the following error every time I try to use stack except for stack --version:

PS D:\Currentdir\version2\code> stack update
InvalidRelDir "D:\\Currentdir\\code\\.stack-work"
PS D:\Currentdir\version2\code> stack clean
InvalidRelDir "D:\\Currentdir\\version2\\code\\.stack-work"
PS D:\Currentdir\version2\code> stack test
InvalidRelDir "D:\\Currentdir\\version2\\code\\.stack-work"
PS D:\Currentdir\version2\code> 

I think I deleted the .stack/work subfolder in one of my projects (from within Windows 10 file explorer), and this might be causing the problems since the commands might look for that specific folder, and since stack test did work before. There are however .stack-work subfolders in other projects such as in the one indicated above. So I am not entirely sure.

I just discovered that my stack has somehow been set to look for a .stack-work folder that is within a specific folder, as seen below where I have tried to navigate first to other folders and after that to that particular folder in windows powershell:

PS D:\Redo_haskell_folder\code> stack path  
InvalidRelDir "D:\\HaskellAppFolder\\version2\\code\\.stack-work"

PS D:\Redo_haskell_folder\code> stack --stack-root STACK-ROOT
option --stack-root: InvalidAbsDir "STACK-ROOT"

PS C:\sr> stack path
InvalidRelDir "D:\\HaskellAppFolder\\version2\\code\\.stack-work"

PS D:\HaskellAppFolder\version2\code> stack path
InvalidRelDir "D:\\HaskellAppFolder\\version2\\code\\.stack-work"

I have tried the following steps to troubleshoot the "InvalidRelDir" error when running stack update or stack clean, I:

Made sure that I am using the latest version of stack by running stack --version and tried updating stack with stack upgrade.

Checked the contents of my stack.yaml file to make sure that it is correct and specifies the correct dependencies and packages for my project. It is just the one initilialized with the stack init in my current folder.

Ran stack init in my project directory to create a new stack.yaml file and configure my project for use with stack. This gives back the same error message.

Tried to delete the .stack-work directory using Remove-Item -Recurse -Force .stack-work (I am using windows 10 and powershell terminal) and ran stack update or stack clean again to see if the issue is resolved. The remove-command caused same InvalidRelDir error.

Tried to change the permission of the folders I am working in, within the windows 10 explorer, by un-checking the 'Read only'-permission. The problem persists.

I also tried suing stack-root I get the following in the powershell prompt

code> stack --stack-root STACK-ROOT
option --stack-root: InvalidAbsDir "STACK-ROOT"

Despite these efforts, I am still encountering the "InvalidRelDir" error. I haven't been able to find any posts that mentions the same problem they encountered, any good ideas?

EDIT Since I have gotten very few responses, perhaps I could help open op the trouble shooting by asking about the default location for stack root.

Furthermore is there a way to un-install only stack rather than all of the ghc and cabal packages that comes with it?

EDIT EDIT

Or if none of the above works, would there be a way to uninstall the above and re-install in such a way that I would have taken into consideration the multiple .stack-work folders that might have been created from my trouple shooting proces.

EDIT x3

I finally found the InvalidRelDir in the documentation - not for stack as such but at hackage . As far as I can see this is a haskell documentation, and somehow the stack build is using the function parselRelDir described as:

parseRelDir :: MonadThrow m => FilePath -> m (Path Rel Dir)

Convert a relative FilePath to a normalized relative dir Path.

Throws: InvalidRelDir when the supplied path:

is not a relative path
is ""
contains a .. path component representing the parent directory
is not a valid path (See isValid)

I suspect that I get the error because the stack library is using this library as well. If any of you find this to be an incorrect tenet or have any suggestions about how to proceed from here without uninstalling all of stack it will be appreciated.

As seen in the post above, I have now narrowed the problem down even further, to some kind of 'pointer' to an 'old' or wrong directory. And I think my question therefore is: "Is there a way to 'reset' the .stack-workfolder that stack is looking for with the parseRelDir function mentioned before?"

I have now uninstalled stack according to: this and have in that process also removed C:\sr and the %AppData%\Roaming\stack.

I have then installed it with this windows package as recommended from official documentary.

I do however still get the same error now that I have installed it again.

EDIT x4

I have now made progress! I went to "Edit System Variables" and edited "STACK ROOT" to C:\sr and C:\sr\.stack-work but got the following error with the output of those paths respectively

PS D:\Redo_haskell_folder\code> stack path InvalidRelDir "C:\\sr"

So now that I know why the pointer kept being the same despite re-installing stack, I now have to find out the following: What is the correct path for "STACK ROOT"

PS: after reinstalling the C:\sr is empty except for a config.yaml file


Solution

  • I got in touch with the stack-support and used the following 'reset of the STACK_ROOT' to solve the issue.

    STACK_ROOT is an environment variable that specifies the location of the Stack Root directory. See https://docs.haskellstack.org/en/stable/environment_variables/#stack_root. See also: https://docs.haskellstack.org/en/stable/global_flags/#the-stack-root-option. On Windows, the default value is C:\sr (because some Windows operating systems have problems with long paths). Stack will populate the Stack root the first time it needs the contents of the Stack root.

    ❯ echo $Env:STACK_WORK
    
    > $Env:STACK_WORK="C:\temp"
    
    > echo $Env:STACK_WORK
    C:\temp
    
    > stack path --dist-dir
    InvalidRelDir "C:\\temp"
    
    > $Env:STACK_WORK=""
    
    > stack path --dist-dir
    .stack-work\dist\8a54c84f