stacked icon indicating copy to clipboard operation
stacked copied to clipboard

[bug]: Unhandled exception: Bad state: The "HOME" environment variable is not set. This package (and POSIX) requires that HOME be set.

Open Correct-Syntax opened this issue 1 year ago • 10 comments

Describe the bug

Hello, I've been unable to get the stacked_cli to work on Windows 10. Whenever I run the cli with stacked ... it gives an error:

Unhandled exception:
Bad state: The "HOME" environment variable is not set. This package (and POSIX) requires that HOME be set.

I seen this and this, but as you can see below trying the local version didn't help and my Dart version shouldn't be a problem: Dart SDK version: 3.2.0 (stable) (Tue Nov 14 18:26:59 2023 +0000) on "windows_x64"

Have any ideas what is causing the issue?

To reproduce

Following the docs, I ran the command to activate the cli. However, after the error I continued like so:

PS C:\Users\Acer> dart pub global activate stacked_cli
Package stacked_cli is currently active at version 1.12.1.
The package stacked_cli is already activated at newest available version.
To recompile executables, first run `dart pub global deactivate stacked_cli`.
Installed executable stacked.
Activated stacked_cli 1.12.1.
PS C:\Users\Acer> stacked
Unhandled exception:
Bad state: The "HOME" environment variable is not set. This package (and POSIX) requires that HOME be set.#0      _getDirectory (package:xdg_directories/xdg_directories.dart:120:5)
#1      _directoryFromEnvironmentWithFallback (package:xdg_directories/xdg_directories.dart:109:12)       
#2      configHome (package:xdg_directories/xdg_directories.dart:152:5)
#3      PathService.configHome (package:stacked_cli/src/services/path_service.dart:41:35)
#4      PosthogService.init (package:stacked_cli/src/services/posthog_service.dart:42:31)
#5      setupLocator (package:stacked_cli/src/locator.dart:27:24)
#6      main (file:///C:/Users/Acer/AppData/Local/Pub/Cache/hosted/pub.dev/stacked_cli-1.12.1/bin/stacked.dart:18:9)
#7      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
#8      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
Unhandled exception:
Bad state: The "HOME" environment variable is not set. This package (and POSIX) requires that HOME be set.#0      _getDirectory (package:xdg_directories/xdg_directories.dart:120:5)      
#1      _directoryFromEnvironmentWithFallback (package:xdg_directories/xdg_directories.dart:109:12)
#2      configHome (package:xdg_directories/xdg_directories.dart:152:5)
#3      PathService.configHome (package:stacked_cli/src/services/path_service.dart:41:35)
#4      PosthogService.init (package:stacked_cli/src/services/posthog_service.dart:42:31)
#5      setupLocator (package:stacked_cli/src/locator.dart:27:24)
#6      main (file:///C:/Users/Acer/AppData/Local/Pub/Cache/hosted/pub.dev/stacked_cli-1.12.1/bin/stacked.dart:18:9)
#7      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
#8      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Then I downloaded the source from the stacked_cli repo and tried to run it:

PS C:\Users\Acer\Downloads\cli-main\cli-main> dart pub global activate --source path .
Resolving dependencies... (2.9s)
+ _fe_analyzer_shared 65.0.0
+ analyzer 6.3.0
+ ansicolor 2.0.2
+ args 2.4.2
+ async 2.11.0
+ boolean_selector 2.1.1  
+ build 2.4.1
+ build_config 1.1.1      
+ build_daemon 4.0.1      
+ build_resolvers 2.4.1   
+ build_runner 2.4.7      
+ build_runner_core 7.2.11
+ built_collection 5.1.1  
+ built_value 8.8.0       
+ checked_yaml 2.0.3      
+ code_builder 4.8.0      
+ collection 1.18.0       
+ convert 3.1.1
+ coverage 1.7.1
+ crypto 3.0.3
+ dart_style 2.3.4
+ file 7.0.0
+ fixnum 1.1.0
+ freezed 2.4.5
+ freezed_annotation 2.4.1
+ frontend_server_client 3.2.0
+ functional_data 1.1.1
+ get_it 7.6.4
+ glob 2.1.2
+ graphs 2.3.1
+ hive 2.2.3
+ http 1.1.2
+ http_multi_server 3.2.1
+ http_parser 4.0.2
+ io 1.0.4
+ js 0.6.7
+ json2yaml 3.0.1
+ json_annotation 4.8.1
+ json_serializable 6.7.1
+ lints 3.0.0
+ logging 1.2.0
+ matcher 0.12.16
+ meta 1.11.0
+ mime 1.0.4
+ mockito 5.4.3
+ mustache_template 2.0.0
+ node_preamble 2.0.2
+ package_config 2.1.0
+ path 1.8.3
+ plain_optional 1.0.0
+ platform 3.1.3
+ pool 1.5.1
+ process 5.0.1
+ pub_semver 2.1.4
+ pub_updater 0.4.0
+ pubspec_parse 1.2.3
+ pubspec_yaml 3.1.0
+ recase 4.1.0
+ shelf 1.4.1
+ shelf_packages_handler 3.0.2
+ shelf_static 1.1.2
+ shelf_web_socket 1.0.4
+ source_gen 1.4.0
+ source_helper 1.3.4
+ source_map_stack_trace 2.1.1
+ source_maps 0.10.12
+ source_span 1.10.0
+ stack_trace 1.11.1
+ stream_transform 2.1.0
+ string_scanner 1.2.0
+ sum_types 0.3.5
+ term_glyph 1.2.1
+ test 1.24.9
+ test_api 0.6.1
+ test_core 0.5.9
+ timing 1.0.1
+ typed_data 1.3.2
+ vm_service 13.0.0
+ watcher 1.1.0
+ web 0.4.0
+ web_socket_channel 2.4.0
+ webkit_inspection_protocol 1.2.1
+ xdg_directories 1.0.3
+ yaml 3.1.2
Changed 85 dependencies!
Package stacked_cli is currently active at version 1.12.1.
Installed executable stacked.
Activated stacked_cli 1.12.1 at path "C:\Users\Acer\Downloads\cli-main\cli-main".
PS C:\Users\Acer\Downloads\cli-main\cli-main> stacked
Building package executable... (6.4s)
Built stacked_cli:stacked.
Unhandled exception:
Bad state: The "HOME" environment variable is not set. This package (and POSIX) requires that HOME be set.
#0      _getDirectory (package:xdg_directories/xdg_directories.dart:120:5)
#1      _directoryFromEnvironmentWithFallback (package:xdg_directories/xdg_directories.dart:109:12)
#2      configHome (package:xdg_directories/xdg_directories.dart:152:5)
#3      PathService.configHome (package:stacked_cli/src/services/path_service.dart:41:35)
#4      PosthogService.init (package:stacked_cli/src/services/posthog_service.dart:42:31)
#5      setupLocator (package:stacked_cli/src/locator.dart:27:24)
#6      main (file:///C:/Users/Acer/Downloads/cli-main/cli-main/bin/stacked.dart:18:9)
#7      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
#8      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Expected behavior

To be able to run the cli. :)

Screenshots

No response

Additional Context

No response

Correct-Syntax avatar Dec 01 '23 03:12 Correct-Syntax

Hey,

Is it possible for you to set a HOME environment and see if it works?

I don't want to delete my home env. Mine is /Users/danemackier on my mac.

FilledStacks avatar Dec 01 '23 14:12 FilledStacks

I get the same error.

OS: Win 11

Dart version: Dart SDK version: 3.3.0-91.0.dev (dev) (Thu Nov 2 09:10:03 2023 -0700) on "windows_x64"

Flutter version:

Flutter 3.17.0-1.0.pre.3 • channel beta • https://github.com/flutter/flutter.git
Framework • revision 12b47270b7 (5 days ago) • 2023-11-27 17:21:11 -0600
Engine • revision dff66925dc
Tools • Dart 3.3.0 (build 3.3.0-91.0.dev) • DevTools 2.29.0

Stacked error:

PS D:\dev\workspace\flutter> stacked
Unhandled exception:
Bad state: The "HOME" environment variable is not set. This package (and POSIX) requires that HOME be set.
#0      _getDirectory (package:xdg_directories/xdg_directories.dart:120:5)
#1      _directoryFromEnvironmentWithFallback (package:xdg_directories/xdg_directories.dart:109:12)
#2      configHome (package:xdg_directories/xdg_directories.dart:152:5)
#3      PathService.configHome (package:stacked_cli/src/services/path_service.dart:41:35)
#4      PosthogService.init (package:stacked_cli/src/services/posthog_service.dart:42:31)
#5      setupLocator (package:stacked_cli/src/locator.dart:27:24)
#6      main (file:///C:/Users/oppah/AppData/Local/Pub/Cache/hosted/pub.dev/stacked_cli-1.12.3/bin/stacked.dart:18:9)
#7      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
#8      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
Unhandled exception:
Bad state: The "HOME" environment variable is not set. This package (and POSIX) requires that HOME be set.
#0      _getDirectory (package:xdg_directories/xdg_directories.dart:120:5)
#1      _directoryFromEnvironmentWithFallback (package:xdg_directories/xdg_directories.dart:109:12)
#2      configHome (package:xdg_directories/xdg_directories.dart:152:5)
#3      PathService.configHome (package:stacked_cli/src/services/path_service.dart:41:35)
#4      PosthogService.init (package:stacked_cli/src/services/posthog_service.dart:42:31)
#5      setupLocator (package:stacked_cli/src/locator.dart:27:24)
#6      main (file:///C:/Users/oppah/AppData/Local/Pub/Cache/hosted/pub.dev/stacked_cli-1.12.3/bin/stacked.dart:18:9)
#7      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
#8      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

I remember it working like a week or two ago.

Where should this "HOME" environment variable point to? I am confused, why do I need it now?

UPDATE Setting the "HOME" variable, solves the issue. @FilledStacks Why does it require this variable now?

oppahansi avatar Dec 02 '23 16:12 oppahansi

Yes, setting the HOME variable does work. Thank you.

It may be good to catch the error and prompt the user to set the variable on Windows since this seems to be a requirement now.

Correct-Syntax avatar Dec 02 '23 23:12 Correct-Syntax

@oppahansi it's a requirement for another package.

We store global configuration in the directory that the operating system recommends. That directory is usually relative the the HOME directory, so when we look for the Document directory that path is built from the Home directory.

FilledStacks avatar Dec 03 '23 09:12 FilledStacks

We can definitely have a better message for that issue.

FilledStacks avatar Dec 03 '23 09:12 FilledStacks

can you help me, how to set HOME enviroment variable. i quite new on this. im using windows 11

Thank you.

nabambil avatar Dec 03 '23 15:12 nabambil

can you help me, how to set HOME enviroment variable. i quite new on this. im using windows 11

Thank you.

Follow there instructions @nabambil : https://windowsreport.com/environment-variables-windows-11/

At the step when you will need to set a value for HOME, just browser to your user home folder.

Example: C:\Users\yourusername

oppahansi avatar Dec 03 '23 16:12 oppahansi

Set a "C:\Users\xxxx" (xxxx is u user name) work to me, but, u can need create u project at same folder, u need open a Terminal at "C:\Users\xxxx" folder and create u project here

Menezesx07 avatar Dec 08 '23 19:12 Menezesx07

Create a HOME environment variable and set its value to C:\Users\your_username. That's all. This worked for me...

hmzaak avatar Feb 01 '24 14:02 hmzaak

Thanks, creating an HOME environment variable and set its value to C:\Users\your_name that's all I need to do This worked for me well.

afghandev5 avatar Feb 28 '24 01:02 afghandev5