supabase / supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
https://supabase.com/
MIT License
742 stars 183 forks source link

Error initializing on Flutter Web #1052

Closed chiefheru closed 1 month ago

chiefheru commented 1 month ago

Describe the bug Hi, I have followed the instructions on the site to add supabase_flutter to a new Flutter web project and I get an error initializing. I also noticed that when I run the command flutter pub add supabase_flutter it adds the version ^1.0.1 to pubspec.yaml rather than the latest (2.7.0). When I try to manually use the 2.7.0, I get this versioning error.

Resolving dependencies...
Because supabase depends on supabase_flutter 2.7.0 which depends on supabase 2.4.0, supabase 2.4.0 is required.
So, because supabase is 1.0.0+1, version solving failed.

You can try the following suggestion to make the pubspec resolve:
* Consider downgrading your constraint on supabase_flutter: flutter pub add supabase_flutter:^1.0.1
exit code 1

This is the error when I run the project

../../.pub-cache/hosted/pub.dev/supabase_flutter-1.0.1/lib/supabase_flutter.dart:6:1: Error: Error when reading 'lib/supabase.dart': No such file or
directory
export 'package:supabase/supabase.dart';
^
../../.pub-cache/hosted/pub.dev/supabase_flutter-1.0.1/lib/src/supabase.dart:3:8: Error: Error when reading 'lib/supabase.dart': No such file or directory
import 'package:supabase/supabase.dart';
       ^
../../.pub-cache/hosted/pub.dev/supabase_flutter-1.0.1/lib/src/supabase.dart:80:8: Error: Type 'SupabaseClient' not found.
  late SupabaseClient client;

To Reproduce Steps to reproduce the behavior:

  1. create a new flutter web project (flutter create --platforms web test)
  2. flutter pub add supabase_flutter
  3. add import 'package:supabase_flutter/supabase_flutter.dart'; to main.dart
  4. initialize supabase in main() method
  5. Run the project using flutter run -d chrome
  6. get error in terminal

This is the flutter doctor output

[✓] Flutter (Channel stable, 3.24.3, on macOS 14.4.1 23E224 darwin-arm64, locale en-US)
    • Flutter version 3.24.3 on channel stable at /Users/juliorivera/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (3 weeks ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.93.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.98.0

[✓] Connected device (1 available)
    • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 129.0.6668.71

[✓] Network resources
    • All expected network resources are available.

• No issues found!
Vinzent03 commented 1 month ago

Please share your pubspec.yaml.

chiefheru commented 1 month ago

@Vinzent03

name: supabase
description: "A new Flutter project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1

environment:
  sdk: ^3.5.3

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.8
  supabase_flutter: ^1.0.1

dev_dependencies:
  flutter_test:
    sdk: flutter

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^4.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/to/resolution-aware-images

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/to/asset-from-package

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/to/font-from-package
Vinzent03 commented 1 month ago

You can't name your package supabase, because that's already the name of our dart supabase package, which supabase_flutter is based on. So by changing the name: field in your pubspec.yaml, this should be fixed.

chiefheru commented 1 month ago

@Vinzent03 yikes, good catch and thanks for the help.