Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sdkPath is not working when flutter is not on the global path #616

Open
1 task done
Ppito opened this issue Dec 12, 2023 · 25 comments
Open
1 task done

fix: sdkPath is not working when flutter is not on the global path #616

Ppito opened this issue Dec 12, 2023 · 25 comments
Labels
bug Something isn't working Type: Accepted

Comments

@Ppito
Copy link

Ppito commented Dec 12, 2023

Is there an existing issue for this?

  • I have searched the existing issues.

Version

>=3.2.0

Description

Hi,

I use fvm to manage my various Flutter versions and until melos version 3.1.1 I had no particular problem with using the sdkPath option in my melos.yml configuration file.

sdkPath: .fvm/flutter_sdk

Since I updated melos on 3.2.0 (same problem on 3.4.0) this option no longer works with the message The Flutter SDK is not available..

Steps to reproduce

  1. Install fvm and use the version 3.16.3 of Flutter on your current project (same problem with 3.1.6 for example)
  2. Install melos 3.2.0 (or above)
  3. add sdkPath: .fvm/flutter_sdk on melos.yaml
  4. Run melos bs
  5. SDK not found.
PS C:\Work\my_project> melos bs
The Flutter SDK is not available.
PS C:\Work\my_project>

Expected behavior

The specified SDK path has been found and the command is running.

Screenshots

No response

Additional context and comments

I've looked through the PR and searched the entire project (on tag 3.2.0 and melos-latest), but I can't figure out what caused the problem or how to solve it.

I work on Windows 11 (without WSL), but like I said, everything work fine with melos 3.1.1.

I tried mmany configuration

  • melos 3.1.1
    • Flutter 3.10.6 = OK
    • Flutter 3.13.9 = OK
    • Flutter 3.16.3 = OK
  • melos 3.2.0
    • Flutter 3.10.6 = KO
    • Flutter 3.13.9 = KO
    • Flutter 3.16.3 = KO
  • melos 3.4.0
    • Flutter 3.10.6 = KO
    • Flutter 3.13.9 = KO
    • Flutter 3.16.3 = KO

I also tried to use the env variable MELOS_SDK_PATH

@Ppito Ppito added the bug Something isn't working label Dec 12, 2023
@Ppito
Copy link
Author

Ppito commented Dec 12, 2023

Ok I get it...
I had forced myself not to set Flutter in my windows environment variables, to make sure I always used the FVM version.
Except that since melos 3.2.0 I'm obliged to have this variable set.

This means that a subsystem ignores the sdkPath parameter and expects to use the system configuration.

@spydon
Copy link
Collaborator

spydon commented Dec 14, 2023

Thanks for a well written issue, so it works for Melos 3.1.1?

@Ppito
Copy link
Author

Ppito commented Dec 14, 2023

Thanks for a well written issue, so it works for Melos 3.1.1?

yes, it works fine in 3.1.1

@spydon
Copy link
Collaborator

spydon commented Dec 14, 2023

That is so strange, because the only changes that are not docs between 3.1.1 and 3.2.0 are:
#538
#590
#526

And #538 only adds some exports, and #590 only adds trailing commas.
So there must be something in #526, and I really don't see how that could affect it...

@Ppito
Copy link
Author

Ppito commented Dec 14, 2023

yes, I had inspected the PR too and found nothing. I'll try to make a video presentation.

@spydon
Copy link
Collaborator

spydon commented Dec 14, 2023

I just tried to replicate your setup and it works fine for me (so I probably failed to replicate it)...
Used a local fvm and pointed at it with sdkPath.

@Ppito
Copy link
Author

Ppito commented Dec 14, 2023

My previous isntallation was :

  • installation of dart with choco - update windows PATH environnement
  • installation of fvm with dart pub global activate fvm
  • DO NOT configure flutter on windows PATH environnement

Case 1:

  • .fvm/fvm_config.json with version 3.16.3
  • pubspec.yaml with melos on 3.1.1
  • melos.yml with sdkPath: .fvm/flutter_sdk
  • run melos bs => works

Case 2:

  • .fvm/fvm_config.json with version 3.16.3
  • pubspec.yaml with melos on 3.2.0
  • melos.yml with sdkPath: .fvm/flutter_sdk
  • run melos bs => doesn't work

Case 3:

  • Configure flutter on windows PATH environnement
    • provide by fvm, in my case : C:\Users\Ppito\fvm\versions\3.16.3\bin
  • .fvm/fvm_config.json with version 3.16.3
  • pubspec.yaml with melos on 3.2.0
  • melos.yml with sdkPath: .fvm/flutter_sdk
  • run melos bs => work

I haven't had time to do another test since it's working again for me.
I'll try these scenarios again to confirm.

@spydon
Copy link
Collaborator

spydon commented Dec 14, 2023

Ah right, I forgot to unset the environment Flutter.
I guess that melos itself needs a flutter version to set itself to the version specified in the root pubspec and I guess it hasn't read the melos.yaml file yet at that point. I still don't understand which PR that could have affected this though.
You don't have any common dependencies specified in melos.yaml right?

@Ppito
Copy link
Author

Ppito commented Dec 14, 2023

I don't really know, I'm fairly new to the flutter world and I've just started on a fairly complex project.
I wouldn't know what to look for.
What do you mean by "common dependencies specified in melos.yaml" ?

I have my main project and 5 internal packages on it.

@spydon
Copy link
Collaborator

spydon commented Dec 14, 2023

@Ppito it's a quite new feature so you're probably not using it, but can you post your full melos.yaml file?

@Ppito
Copy link
Author

Ppito commented Dec 14, 2023

Okay, I'll warn you right now, the configuration isn't mine. 🤣

name: my_app

packages:
  - .
  - packages/**

sdkPath: .fvm/flutter_sdk

command:
  clean:
    hooks:
      post: melos exec --flutter -- "flutter clean"
  bootstrap:
    runPubGetInParallel: false
    usePubspecOverrides: true

scripts:
  # [Format] -----------------------------------------------------------------------------------------------------------

  format:
    run: melos run format:dart --no-select && melos run format:flutter --no-select
    description: Run Dart/Flutter formats in all packages.

  format:dart:
    run: melos exec --concurrency=1 -- "dart format --output=none --set-exit-if-changed ."
    description: Run Dart format in all dart packages.
    packageFilters:
      flutter: false
      ignore: "*example*"

  format:flutter:
    run: melos exec --concurrency=1 -- "dart format --output=none --set-exit-if-changed ."
    description: Run Flutter format in all flutter packages.
    packageFilters:
      flutter: true
      ignore: "*example*"

  # [Analyze] ----------------------------------------------------------------------------------------------------------

  analyze:
    run: melos run analyze:dart --no-select && melos run analyze:flutter --no-select
    description: Run Dart/Flutter analyzes in all packages.

  analyze:dart:
    run: melos exec --concurrency=1 -- "dart analyze ."
    description: Run Dart analyze in all dart packages.
    packageFilters:
      flutter: false
      ignore: "*example*"

  analyze:flutter:
    run: melos exec --concurrency=1 -- "flutter analyze ."
    description: Run Flutter analyze in all flutter packages.
    packageFilters:
      flutter: true
      ignore: "*example*"

  # [Generate] ---------------------------------------------------------------------------------------------------------

  generate:
    run: melos run generate:dart --no-select && melos run generate:flutter --no-select
    description: Run Dart/Flutter build_runner in all packages.

  generate:dart:
    run: melos exec --concurrency=1 -- "dart pub run build_runner build --delete-conflicting-outputs"
    description:  Run Dart build_runner in all dart packages.
    packageFilters:
      flutter: false
      ignore: "*example*"
      dependsOn: build_runner

  generate:flutter:
    run: melos exec --concurrency=1 -- "flutter pub run build_runner build --delete-conflicting-outputs"
    description:  Run Flutter build_runner in all flutter packages.
    packageFilters:
      flutter: true
      ignore: "*example*"
      dependsOn: build_runner

  # [Test] -------------------------------------------------------------------------------------------------------------

  test:
    run: melos run test:dart --no-select && melos run test:flutter --no-select
    description: Run Dart/Flutter tests in all packages.

  test:dart:
    run: melos exec --concurrency=1 --fail-fast -- "dart test"
    description: Run Dart test in all dart packages.
    packageFilters:
      flutter: false
      dirExists: test
      ignore: "*example*"

  test:flutter:
    run: melos exec --concurrency=1 --fail-fast -- "flutter test --coverage --test-randomize-ordering-seed random"
    description: Run Flutter test in all flutter packages.
    packageFilters:
      flutter: true
      dirExists: test
      ignore: "*example*"

  test:flutterWithHtmlCoverage:
    run: melos exec --concurrency=1 --fail-fast "flutter test --coverage --test-randomize-ordering-seed random --reporter expanded && genhtml coverage/lcov.info --output-directory coverage/html && open coverage/html/index.html"
    description: Run Flutter test in all flutter packages with HTML coverage.
    packageFilters:
      flutter: true
      dirExists: test
      ignore: "*example*"

  # [Flavor] -----------------------------------------------------------------------------------------------------------

  dev:
    run: melos run qa:dev --no-select
    description: Run Dev environment.

  mock:
    run: melos run qa:mock --no-select
    description: Run Mock environment.

  staging:
    run: melos run qa:staging --no-select
    description: Run Staging environment.

  production:
    run: melos exec -- "flutter run --flavor production"
    description: Run with Production flavor in Production environment.
    packageFilters:
      scope: "my_app"

  qa:dev:
    run: melos exec -- "flutter run --flavor qa -a ENV=dev"
    description: Run with QA flavor in Dev environment.
    packageFilters:
      scope: "my_app"

  qa:mock:
    run: melos exec -- "flutter run --flavor qa -a ENV=mock"
    description: Run with QA flavor in Mock environment.
    packageFilters:
      scope: "my_app"

  qa:staging:
    run: melos exec -- "flutter run --flavor qa -a ENV=test"
    description: Run with QA flavor in Staging environment.
    packageFilters:
      scope: "my_app"

  # [UI] ---------------------------------------------------------------------------------------------------------------

  widgetbook:
    run: melos exec -- "flutter run --device-id chrome -a ENV=dev"
    description: Run widgetbook on web.
    packageFilters:
      scope: "pkg_widgetbook"

@spydon
Copy link
Collaborator

spydon commented Dec 14, 2023

Alright, no common dependencies.

And everything looks in order, except that it seems like you are having one package in the root, which is not recommended since the workspace pubspec lives in the root and then will collide with the one for the package/app that you have there, so if I were you I would move that into either packages or create a directory called apps where you put it instead. (But this won't change anything with the problem that you were having with the sdkPath)

@spydon spydon changed the title fix: sdkPath not working fix: sdkPath is not working when flutter is not on the global path Dec 14, 2023
@Ppito
Copy link
Author

Ppito commented Dec 14, 2023

It's not really a package on the root, it's my main application ... ^^"

@spydon
Copy link
Collaborator

spydon commented Dec 14, 2023

It's not really a package on the root, it's my main application ... ^^"

Then it should be in a directory named the same as your app inside of apps/ :)

@Ppito
Copy link
Author

Ppito commented Dec 14, 2023

So, instead of this :

├── analysis_options.yaml
├── android/
├── assets/
├── build.yaml
├── codemagic.yaml
├── ios/
├── l10n.yaml
├── lib/
│   └── main.dart
├── LICENSE.md
├── melos.yaml
├── packages/
│   ├── pkg_name1/
│   ├── pkg_name2/
│   ├── pkg_name3/
│   ├── pkg_name4/
│   └── pkg_name5/
├── pubspec.yaml
├── README.md
├── test/
└── windows/

I should have this:

├── assets/
├── build.yaml
├── codemagic.yaml
├── LICENSE.md
├── apps/
│   └── my_app/
│       ├── analysis_options.yaml
│       ├── android/
│       ├── ios/
│       ├── l10n.yaml
│       ├── lib/
│       │   └── main.dart
│       ├── test/
│       ├── windows/
│       └── pubspec.yaml
├── melos.yaml
├── packages/
│   ├── pkg_name1/
│   ├── pkg_name2/
│   ├── pkg_name3/
│   ├── pkg_name4/
│   └── pkg_name5/
├── pubspec.yaml
└── README.md

@spydon
Copy link
Collaborator

spydon commented Dec 14, 2023

@Ppito exactly :)

@Ppito
Copy link
Author

Ppito commented Dec 14, 2023

We've strayed from the original topic, but thanks for the advice. 😁

@jiechic
Copy link

jiechic commented Dec 18, 2023

the same problem #574

@mrverdant13
Copy link
Contributor

Hey there 👋🏼
I am just facing this issue now

Local context

OS: Windows 11
dart version: 3.2.3 installed through Chocolatey
fvm version: 2.4.1 installed through the global Dart SDK, and exposes a globally enabled Flutter SDK as default
melos version: 3.4.0 installed through the global Dart SDK

Setup cases

Case 1: When the root package (the one that includes melos), only sets the Dart SDK version constraints, running melos bs fails and a message is shown indicating that the Flutter SDK is required for a couple of sub-packages.

Case 2: When the root package (the one that includes melos), sets also the Flutter SDK constraints, running melos bs does work as expected, but the logs state that the actual used deps installation command was flutter pub get.

Case 2 is the approach I am using now as a workaround.
I consider it a workaround since I would expect the use of the proper SDK (Dart or Flutter) depending on the sub-package pubspec.yaml environment setup.

@wizlif
Copy link

wizlif commented Jan 20, 2024

I faced the same issue but fixed it by matching the global version of melos to the one in my pubspec.yaml also set the FLUTTER_ROOT environment variable

@tenhobi
Copy link

tenhobi commented Feb 13, 2024

Hi, we face with the same issue

FVM for this project:

Flutter 3.16.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 78666c8dc5 (8 weeks ago) • 2023-12-19 16:14:14 -0800
Engine • revision 3f3e560236
Tools • Dart 3.2.3 • DevTools 2.28.4
$ melos bs

Can't load Kernel binary: Invalid kernel binary format version.
melos 4.1.0 doesn't support Dart 2.14.3.

in melos.yaml we have

sdkPath: .fvm/flutter_sdk

But fvm has global version Flutter 2.5.2:

Flutter 2.5.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 3595343e20 (2 years, 4 months ago) • 2021-09-30 12:58:18 -0700
Engine • revision 6ac856380f
Tools • Dart 2.14.3

Aka melos does not respect sdkPath and uses the global flutter.

@leoafarias
Copy link

There are a few different issues mentioned here. But it seems they are most likely a mismatch on the Flutter/Dart version running the melos command vs the one that is in the .fvm/flutter_sdk

FVM has a command to help force the version that runs the commands called exec, which executes the command with the flutter version in the path. So you can use fvm exec melos bs

To double-check this, you can do the following:

$ fvm exec dart --version
$ dart --version

These versions are most likely mismatched.

@spydon let me know if there is anything I can do to make things easier for you guys.

@spydon
Copy link
Collaborator

spydon commented Feb 26, 2024

@leoafarias I'm not sure if there is anything we can do from our side? If the melos binary is installed with another Flutter version I don't think we can change which sdk it executes itself with, only the commands that will be run from within melos. 🤔
There must be other binaries similar to melos that face the same problem when there are multiple versions involved, have you heard of any other?

@leoafarias
Copy link

@spydon FVM has the same problem; as you imagine, FVM can change the SDK that is used to run itself 🤯

The only solution I have found is to distribute a compiled binary. This might minimize these problems, and based on some issues I have seen here, it might be the solution for "environment configuration" problems.

If this makes sense to explore, we can talk offline, and I can create an initial PR for this.

@spydon
Copy link
Collaborator

spydon commented Feb 26, 2024

@spydon FVM has the same problem; as you imagine, FVM can change the SDK that is used to run itself 🤯

Aah yeah, of course!

The only solution I have found is to distribute a compiled binary. This might minimize these problems, and based on some issues I have seen here, it might be the solution for "environment configuration" problems.

You'd have to distribute it outside of pub then I guess? That seems like it would add a lot of maintenance effort. 🤔

If this makes sense to explore, we can talk offline, and I can create an initial PR for this.

Yeah, let's have a chat!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Type: Accepted
Projects
None yet
Development

No branches or pull requests

7 participants