Skip to content

Can't get flutter/web working in my app but example app works fine #3440

Description

@YesThatGy

Describe the bug

I'm developing a flutter app with drift. It's working fine on Android and iOS and I'm trying to get it running on the web. When run to chrome locally in AndroidStudio, I persistently get an error message

"TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'."

The example app works fine. My database.dart constructor works fine when copied to the sample app. I've tried copying files/directories back and forth, the problem seems to be related to either sqlite3.wasm or a worker file.

bens@tesla:~/development/shareto$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.27.3, on Fedora Linux 40 (KDE Plasma)
    6.12.10-100.fc40.x86_64, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.94.0)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

database.dart constructor:

  AppDatabase([QueryExecutor? e])
      : super(
    e ??
        driftDatabase(
          name: 'my_database',
          native: const DriftNativeOptions(
            databaseDirectory: getApplicationSupportDirectory,
          ),
          web: DriftWebOptions(
            sqlite3Wasm: Uri.parse('sqlite3.wasm'),
            driftWorker: Uri.parse('drift_worker.js'),
            onResult: (result) {
              if (result.missingFeatures.isNotEmpty) {
                debugPrint(
                  'Using ${result.chosenImplementation} due to unsupported '
                      'browser features: ${result.missingFeatures}',
                );
              }
            },
          ),
        ),
  );

pubspec.yaml

name: ShareTo
description: Easy File Sharing
# 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.4

# 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
  cross_file: ^0.3.4+2
  file_picker: ^8.1.6
  url_launcher: ^6.3.1
  path_provider: ^2.1.5
  permission_handler: ^11.3.1
  device_info_plus: ^11.1.0
  tus_client_dart: ^2.5.0
  go_router: ^14.3.0
  flutter_secure_storage: ^9.2.2
  flutter_launcher_icons: ^0.14.1
  drift: ^2.24.0
  drift_dev: ^2.23.1
  drift_flutter: ^0.2.4
  image_picker: ^1.1.2
  http: ^1.3.0
  video_player: ^2.9.2
  provider: ^6.1.2
  percent_indicator: ^4.2.3
  dio: ^5.7.0
  after_layout: ^1.2.0
  flutter_contacts: ^1.1.9+2
  pretty_json: ^2.0.0
  prompt_dialog: ^1.0.17
  get_thumbnail_video: ^0.7.2
  sms_autofill: ^2.4.0
  fast_rsa: ^3.6.6
  uuid: ^4.5.1
  firebase_core: ^3.6.0
  firebase_messaging: ^15.1.3
  firebase_analytics: ^11.3.3
  background_downloader: ^8.8.0
  share_plus: ^10.1.4
  sqlite3_flutter_libs: ^0.5.29
  sqlite3: ^2.7.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  drift_dev: ^2.24.0
  build_runner: ^2.4.14
  # We use this to compile the shared web worker for the web database. This dependency
  # isn't required for most apps. You only need it if you want to target the web, use
  # web workers for drift AND want to compile those web workers through `build_runner`.
  # Either way, using this package with Flutter requires a delicate setup described in
  # `build.yaml`.
  build_web_compilers: ^4.0.0
  build: ^2.2.1
  integration_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: ^5.0.0
  mockito: ^5.4.4
  http_mock_adapter: ^0.6.1

dependency_overrides:
  tus_client_dart:
    path: ../tus_client

# 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
  assets:
    - images/
  # 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

I've also tried:

  1. rsync files/directories from examples/app:
drift_schemas/
tool/
web/

build_runner output:

bens@tesla:~/development/shareto$ dart run build_runner build
[INFO] Generating build script completed, took 374ms
[INFO] Reading cached asset graph completed, took 657ms
[INFO] Checking for updates since last build completed, took 1.3s
[INFO] Running build completed, took 19.3s
[INFO] Caching finalized dependency graph completed, took 582ms
[INFO] Succeeded after 19.9s with 107 outputs (214 actions)

Pulling my hair out!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions