puro icon indicating copy to clipboard operation
puro copied to clipboard

Unable to "puro use stable" (CouldNotAutoloadMatchingModule PowerShell error)

Open DanTup opened this issue 1 year ago • 3 comments

This seems similar to https://github.com/pingbird/puro/issues/47 but that was marked as resolved. I was trying to test something with Puro but I've spent quite a while wrestling to try and get it to run.

Each time I run puro use stable I get a failure like this:

[W] dart version check failed, deleting cache
[E] powershell: Import-Module : File C:\program
    files\powershell\7\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1 cannot be loaded because
    running scripts is disabled on this system. For more information, see about_Execution_Policies at
    https:/go.microsoft.com/fwlink/?LinkID=135170.
    At line:1 char:1
    + Import-Module Microsoft.PowerShell.Archive; Expand-Archive C:\Users\d ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : SecurityError: (:) [Import-Module], PSSecurityException
        + FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
    Expand-Archive : The 'Expand-Archive' command was found in the module 'Microsoft.PowerShell.Archive', but the module
    could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Archive'.
    At line:1 char:45
    + Import-Module Microsoft.PowerShell.Archive; Expand-Archive C:\Users\d ...
    +                                             ~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Expand-Archive:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule


[x] Assertion failed: "powershell subprocess failed with exit code 1"
    #0      runProcess (package:puro/src/process.dart:121)
    <asynchronous suspension>
    #1      unzip (package:puro/src/env/engine.dart:153)

The first error ("cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies") suggests an execution policy issue, but I've tried setting this to both Bypass and Unrestricted and there's no change:

PS C:\Dev> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    Unrestricted

The error also says:

The 'Expand-Archive' command was found in the module 'Microsoft.PowerShell.Archive', but the module
    could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Archive'.

However running that command manually in the shell works fine:

PS C:\Dev\Test Projects\puro_test> Import-Module Microsoft.PowerShell.Archive
PS C:\Dev\Test Projects\puro_test>

I'm not really sure what else to try. The file in the error (C:\program files\powershell\7\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1) does exist.

Also, when this error happens, the environments folder seems to be left in a broken state because trying to run the command again results in errors like:

PS C:\Dev\Test Projects\puro_test> puro use stable
[E] Exception while installing IntelliJ config
[E] PathNotFoundException: Cannot open file, path = 'C:\Users\danny\.puro\envs\stable\flutter\bin\cache\dart-sdk\lib\_internal\sdk_library_metadata\lib\libraries.dart' (OS Error: The system cannot find the path specified.
    , errno = 3)
    #0      _checkForErrorResponse (dart:io/common.dart:55)
    #1      _File.open.<anonymous closure> (dart:io/file_impl.dart:381)
    <asynchronous suspension>
    #2      _File.readAsBytes.<anonymous closure> (dart:io/file_impl.dart:562)
    <asynchronous suspension>
    #3      _File.readAsString (dart:io/file_impl.dart:621)
    <asynchronous suspension>
    #4      LineSplitter.convert (dart:convert/line_splitter.dart:52)
    <asynchronous suspension>
    #5      IntelliJConfig.save (package:puro/src/workspace/intellij.dart:84)

So I have to manually delete the stable folder before trying again (which is quite a pain while repeatedly trying to resolve the issue).

I'm on Windows 11 Pro.

DanTup avatar Jun 20 '24 15:06 DanTup

I haven't been able to reproduce this unfortunately and don't have an idea of what could be going wrong, it's possible windows defender has decided puro is sus and shouldn't be allowed to load powershell scripts.

pingbird avatar Oct 12 '24 01:10 pingbird

I'm having this issue as well on macOS Sequoia. CleanShot 2024-10-25 at 15 30 26@2x

BenevidesLecontes avatar Oct 25 '24 18:10 BenevidesLecontes

I had the same issue. My system details are:

  • Edition: Windows 11 Home
  • Version: 23H2
  • OS Build: 22631.4751
  • PowerShell: 7.5.0
❯ Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser    RemoteSigned
 LocalMachine    RemoteSigned

The same error persisted even when I changed the policy to Unrestricted or Bypass.

seiya8bit avatar Jan 27 '25 14:01 seiya8bit