dart-archive / stagehand

Dart project generator - web apps, console apps, servers, and more.
https://pub.dev/packages/stagehand
BSD 3-Clause "New" or "Revised" License
649 stars 118 forks source link

Could not find a Dart SDK. Please ensure dart is installed and in your PATH. #693

Closed umermasood closed 3 years ago

umermasood commented 3 years ago

I get this error if I create a dart project using vscode template. Also If I try to create dart project using stagehand from command line it doesn't detect my dart sdk. I have my flutter sdk installed in /home/keystroke/Development/

I have flutter installed in my PATH. This is my .bashrc

# Flutter & Dart Path
export PATH="$PATH:~/Development/flutter/bin"

# JDK Java Development Kit Path
export JAVA_HOME=/snap/android-studio/99/android-studio/jre
export PATH="$JAVA_HOME/bin:$PATH"

# Stagehand Path
export PATH="$PATH":"$HOME/.pub-cache/bin"

This is my flutter doctor -v output:

keystroke@Latitude-E5570:~$ flutter doctor -v
[✓] Flutter (Channel stable, 2.0.0, on Linux, locale en_US.UTF-8)
    • Flutter version 2.0.0 at /home/keystroke/Development/flutter
    • Framework revision 60bd88df91 (2 days ago), 2021-03-03 09:13:17 -0800
    • Engine revision 40441def69
    • Dart version 2.12.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /home/keystroke/Android/Sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /snap/android-studio/current/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Android Studio
    • Android Studio at /snap/android-studio/current/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /snap/android-studio/current/android-studio
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.53.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.20.0

[✓] Connected device (2 available)
    • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86    • Android 11
      (API 30) (emulator)
    • Chrome (web)                • chrome        • web-javascript • Google
      Chrome 89.0.4389.72

• No issues found!

But if I run which dart or which flutter, it doesn't give me any output

keystroke@Latitude-E5570:~$ which flutter
keystroke@Latitude-E5570:~$ which dart

I am unable to create dart project using stagehand or vscode but if I use dart create, I am able to create a project

keystroke@Latitude-E5570:~$ dart create -t console-simple playground
Creating /home/keystroke/playground using template console-simple...

  .gitignore
  CHANGELOG.md
  README.md
  analysis_options.yaml
  bin/playground.dart
  pubspec.yaml

Running pub get...                     1.8s
  Resolving dependencies...
  Changed 1 dependency!

Created project playground! In order to get started, type:

  cd playground

Also this is my vscode error log when I create a dart project using vscode

[8:37:48 PM] [General] [Info] Searching for SDKs...
[8:37:48 PM] [General] [Info] Environment PATH:
[8:37:48 PM] [General] [Info]     /usr/local/sbin
[8:37:48 PM] [General] [Info]     /usr/local/bin
[8:37:48 PM] [General] [Info]     /usr/sbin
[8:37:48 PM] [General] [Info]     /usr/bin
[8:37:48 PM] [General] [Info]     /sbin
[8:37:48 PM] [General] [Info]     /bin
[8:37:48 PM] [General] [Info]     /usr/games
[8:37:48 PM] [General] [Info]     /usr/local/games
[8:37:48 PM] [General] [Info]     /snap/bin
[8:37:48 PM] [General] [Info] Searching for flutter
[8:37:48 PM] [General] [Info]     Looking for flutter in:
[8:37:48 PM] [General] [Info]         /home/keystroke/snap/flutter/common/flutter
[8:37:48 PM] [General] [Info]         /home/keystroke/snap/flutter/common/flutter/bin
[8:37:48 PM] [General] [Info]         /usr/local/sbin
[8:37:48 PM] [General] [Info]         /usr/local/bin
[8:37:48 PM] [General] [Info]         /usr/sbin
[8:37:48 PM] [General] [Info]         /usr/bin
[8:37:48 PM] [General] [Info]         /sbin
[8:37:48 PM] [General] [Info]         /bin
[8:37:48 PM] [General] [Info]         /usr/games
[8:37:48 PM] [General] [Info]         /usr/games/bin
[8:37:48 PM] [General] [Info]         /usr/local/games
[8:37:48 PM] [General] [Info]         /usr/local/games/bin
[8:37:48 PM] [General] [Info]         /snap/bin
[8:37:48 PM] [General] [Info]     Found at:
[8:37:48 PM] [General] [Info]     Candidate paths to be post-filtered:
[8:37:48 PM] [General] [Info]     Returning SDK path undefined for flutter
[8:37:48 PM] [General] [Info] Searching for dart
[8:37:48 PM] [General] [Info]     Looking for dart in:
[8:37:48 PM] [General] [Info]         /usr/local/sbin
[8:37:48 PM] [General] [Info]         /usr/local/bin
[8:37:48 PM] [General] [Info]         /usr/sbin
[8:37:48 PM] [General] [Info]         /usr/bin
[8:37:48 PM] [General] [Info]         /sbin
[8:37:48 PM] [General] [Info]         /bin
[8:37:48 PM] [General] [Info]         /usr/games
[8:37:48 PM] [General] [Info]         /usr/games/bin
[8:37:48 PM] [General] [Info]         /usr/local/games
[8:37:48 PM] [General] [Info]         /usr/local/games/bin
[8:37:48 PM] [General] [Info]         /snap/bin
[8:37:48 PM] [General] [Info]     Found at:
[8:37:48 PM] [General] [Info]     Candidate paths to be post-filtered:
[8:37:48 PM] [General] [Info]     Returning SDK path undefined for dart

This is super weird, please help :smiley:

domesticmouse commented 3 years ago

It would be helpful to see the error message from stagehand.

DanTup commented 3 years ago

If the error is coming from VS Code, the issue is that the PATH that VS Code has does not include the path shown at the top. The log prints the full environment PATH as:

[8:37:48 PM] [General] [Info] Environment PATH:
[8:37:48 PM] [General] [Info]     /usr/local/sbin
[8:37:48 PM] [General] [Info]     /usr/local/bin
[8:37:48 PM] [General] [Info]     /usr/sbin
[8:37:48 PM] [General] [Info]     /usr/bin
[8:37:48 PM] [General] [Info]     /sbin
[8:37:48 PM] [General] [Info]     /bin
[8:37:48 PM] [General] [Info]     /usr/games
[8:37:48 PM] [General] [Info]     /usr/local/games
[8:37:48 PM] [General] [Info]     /snap/bin

My guess is that this is because you're setting the path in .bashrc and that you're not launching VS Code from bash, so it's not inheriting that.

Unfortunately I don't know a reliable way to set PATH on Linux that applies to all processes (it may vary between distributions) - although if you know of one it would be good to update this page with instructions.

mit-mit commented 3 years ago

Closing as external