Flutter app running on web failing with error: Only JS interop members may be 'external'

Issue

I am trying to get my current Flutter app to run on web. I called flutter create . but if I try running it in Chrome I get prompted with about 10000 error messages which all look like this:

Try removing the ‘external’ keyword or adding a JS interop annotation.
external ffi.Pointer<OBX_id_array> removals;
^

../../flutter/.pub-cache/hosted/pub.dartlang.org/objectbox-1.1.0/lib/src/native/bindings/objectbox-c.dart:6289:41:
Error: Only JS interop members may be ‘external’. Try removing the
‘external’ keyword or adding a JS interop annotation. external
ffi.Pointer<OBX_sync_change> list;
^

../../flutter/.pub-cache/hosted/pub.dartlang.org/objectbox-1.1.0/lib/src/native/bindings/objectbox-c.dart:6292:16:
Error: Only JS interop members may be ‘external’. Try removing the
‘external’ keyword or adding a JS interop annotation. external int
count;
^

Failed to compile application.

I tried googling it but I couldn’t find anything on this. Does anyone know what this is about and how I can fit this??

Solution

Re-posting the answer from a GitHub issue here:

You can’t build your app for the web with packages that don’t support web, which ObjectBox doesn’t yet (there’s an issue you can track though).

Sometimes you may want to have the dependency in a small part of the code and it’s fine if it doesn’t work for the web, in that case, you can use "conditional imports", such as:

import 'myapp/sources-that-use-objectbox.dart' if (dart.library.html) 'myapp/sources-that-dont-use-objectbox.dart';

Answered By – vaind

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.