Stacked-Org/stacked

Errors when using cli to create new app

Closed this issue ยท 18 comments

Getting errors trying to create a stacked app from the cli. I have Dart and Flutter SDKs installed and available in the path. Creating a Flutter app with flutter create my_app works successfully.

Package stacked_cli is currently active at version 1.1.0.

C:\Projects>stacked create app my_first_app
Running flutter create my_first_app ...
Command failed. The system cannot find the file specified.

Add Stacked Magic ... 
Created File: 'my_first_app\test/viewmodels/home_viewmodel_test.dart'
Created File: 'my_first_app\test/helpers/test_helpers.dart'
Created File: 'my_first_app\stacked.config.json'
Created File: 'my_first_app\README.md'
Created File: 'my_first_app\lib/main.dart'
Created File: 'my_first_app\lib/ui/setup/setup_dialog_ui.dart'
Created File: 'my_first_app\lib/ui/setup/setup_bottom_sheet_ui.dart'
Created File: 'my_first_app\lib/ui/common/ui_helpers.dart'
Created File: 'my_first_app\lib/ui/common/app_strings.dart'
Created File: 'my_first_app\lib/ui/common/app_colors.dart'
Created File: 'my_first_app\lib/ui/bottom_sheets/notice_sheet/notice_sheet.dart'
Created File: 'my_first_app\lib/ui/bottom_sheets/notice_sheet/notice_sheet_viewmodel.dart'
Created File: 'my_first_app\lib/ui/dialogs/info_alert/info_alert_dialog.dart'
Created File: 'my_first_app\lib/ui/dialogs/info_alert/info_alert_viewmodel.dart'
Created File: 'my_first_app\lib/ui/views/home/home_view.dart'
Created File: 'my_first_app\lib/ui/views/home/home_viewmodel.dart'
Created File: 'my_first_app\lib/ui/views/startup/startup_viewmodel.dart'
Created File: 'my_first_app\lib/ui/views/startup/startup_view.dart'
Created File: 'my_first_app\lib/app/app.dart'
Created File: 'my_first_app\lib/enums/dialog_type.dart'
Created File: 'my_first_app\lib/enums/bottom_sheet_type.dart'
Created File: 'my_first_app\pubspec.yaml'
Running flutter format . -l 80 in my_first_app/...
Command failed. The system cannot find the file specified.

Running flutter pub get in my_first_app/...
Command failed. The system cannot find the file specified.

Running flutter pub run build_runner build --delete-conflicting-outputs in my_first_app/...
Command failed. The system cannot find the file specified.

Running flutter format . -l 80 in my_first_app/...
Command failed. The system cannot find the file specified.

It seems like it's failing at flutter create my_first_app which runs the flutter command directly.

Can you run flutter create my_first_app separately to see if it works.

Yes, no problem when running direct. I also tried using elevated privileges, but same error.

C:\Projects>flutter create my_first_app
Creating project my_first_app...
Running "flutter pub get" in my_first_app...                     1,670ms
Wrote 127 files.

All done!
In order to run your application, type:

  $ cd my_first_app
  $ flutter run

Your application code is in my_first_app\lib\main.dart.

Curiosity got the better of me and I cloned the code and ran locally. I don't see how my system is setup any differently from instructions, but adding '.bat' to the programName in the _runProcessAndLogOutput() method seems to have fixed it for me.

      var process = await Process.start(
        programName + '.bat',
        arguments,
        workingDirectory: workingDirectory,
      );

I then tried using the shell to host the process and that worked too. So I'm guessing something about paths internal to my Dart setup?

      var process = await Process.start(
        programName,
        arguments,
        workingDirectory: workingDirectory,
        runInShell: true
      );

Great job on the CLI, love this setup!

@ratsey thank you! Thank you! Thank you!

That is very interesting. I wonder how we can solve that.

Are you a windows user? Maybe we can build in a fallback to try .bat for Windows if that's the case.

I'm using Windows 11. I'll have another look at the failing code today . I'm not sure about falling back to '.bat' since the run process function is just looking for an executable, not necessarily a bat file. I do think that we should wrap the routine with a T/C in case it should fail for any reason at all - just so the user doesn't have to do too much cleanup.

Is there any reason that we shouldn't run the process with runInShell?

I thought perhaps it was a path environment difference when not running runInShell but the paths are identical. I did find this reference which might suggest a breaking change between Dart 2.9.x to 2.12.1.

I think my recommendation would be to just elect to runInShell. Is there any reason not to?

@ratsey I don't know the difference so it was never a consideration. How would that fare for Mac and Linux users?

It seems like runInShell might work? Did you try it on your side?

Yes, as commented above, runInShell did resolve it for me. I tried to find out what it does - it seems to just run inside the existing shell rather than spawning another. Still unsure why that would make a difference - would need someone to trace down into the source Dart code.

I don't know how it would fare for other OSs - I'm only setup for Windows right now but given it's a core Dart function, I'd be surprised if it had any negative impact to what we're doing here.

@ratsey thanks. We just got another which is a little different, but the stacked command is not being found after activating on someone's machine.

I'll keep this open and see what's up. I'll have to get Windows running again so that I can debug on my side. I appreciate your effort in trying to help me resolve it.

Hello, in my case, I get the following error:
C:\Desarrollo\Flutter\prueba1>stacked create app test_app
Bad state: The "HOME" environment variable is not set. This package (and POSIX) requires that HOME be set.
Running flutter create test_app ...
Command failed. The system cannot find the file specified.

Unhandled exception:
FileSystemException: Cannot delete file, path = 'test_app/test/widget_test.dart' (OS Error: The system cannot find the path specified.
, errno = 3)
#0 _File._delete. (dart:io/file_impl.dart:283:9)

#1 FileService.deleteFile (package:stacked_cli/src/services/file_service.dart:42:5)

#2 CreateAppCommand.run (package:stacked_cli/src/commands/create/create_app_command.dart:51:5)

#3 CommandRunner.runCommand (package:args/command_runner.dart:209:13)

Bad state: The "HOME" environment variable is not set. This package (and POSIX) requires that HOME be set.
Running flutter create test_app ...
Command failed. The system cannot find the file specified.

Unhandled exception:
FileSystemException: Cannot delete file, path = 'test_app/test/widget_test.dart' (OS Error: The system cannot find the path specified.
, errno = 3)
#0 _File._delete. (dart:io/file_impl.dart:283:9)

#1 FileService.deleteFile (package:stacked_cli/src/services/file_service.dart:42:5)

#2 CreateAppCommand.run (package:stacked_cli/src/commands/create/create_app_command.dart:51:5)

#3 CommandRunner.runCommand (package:args/command_runner.dart:209:13)

I am missing some configuration?

@Almircar I think it might be the same - I get that same HOME message when I run my local copy, but then it runs fine., so I think safe to ignore that. The issue you have is the same as me, I think, that it's trying to run the flutter command as a process but failing.

If you clone this repo, these are the steps to apply my 'fix':

Update the _runProcessAndLogOutput() method in packages\stacked_cli\lib\src\services\process_service.dart to add the runInShell parameter:

    try {
      var process = await Process.start(
        programName,
        arguments,
        workingDirectory: workingDirectory,
        runInShell: true
      );
      process.stdout.transform(utf8.decoder).forEach((output) {
        _cLog.flutterOutput(message: output);
      });

Then run this statement to build a local version that will replace any preexisting global installs. Make sure you're in the packages\stacked_cli folder when you run the command:

dart pub global activate --source path . --overwrite

Then try running the stacked create app my_app command again.

@ratsey, thank you very much, I made the change you suggested and it worked.

Thanks @ratsey . I will add the runInShell command and publish a beta version in the next few minutes then test it out on my side. I'll post the version and if you and @Almircar can test it out I would appreciate that.

@ratsey and @Almircar can you test out the latest beta version. Run

dart pub global activate stacked_cli 1.1.1-beta.0

and then try to create an app again.

@FilledStacks I updated, did a test and it is working fine. Congratulations, it is an excellent tool.

@FilledStacks Ran the update, built and tested a new app - no issues. ๐Ÿ‘

@ratsey thank you! honestly. I really appreciate constructive, and feedback that helps me make something better.

I really appreciate you using stacked! even if it's once off. It helps me build something good. And thank you @Almircar as well for your report.

It helps show the urgency to me and the Stacked team.