Search code examples
androidlinuxflutterdartvisual-studio-code

Flutter build error: 'dart:js_interop' is not available on this platform


When I try to build my flutter project:

flutter build apk --debug

--> I get the following error:

lib/screens/ListPage.dart:1:8: Error: Dart library 'dart:js_interop' is not available on this platform.
import 'dart:js_interop';
       ^
Context: The unavailable library 'dart:js_interop' is imported through these packages:

    package:easy_cost_splitter => dart:js_interop

Detailed import paths for (some of) the these imports:

    package:easy_cost_splitter/main.dart => package:easy_cost_splitter/screens/ListPage.dart => dart:js_interop

Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:dart%3Ajs_interop; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:34:7)
#1      asFileUri (package:vm/kernel_front_end.dart:721:37)
#2      writeDepfile (package:vm/kernel_front_end.dart:861:21)
<asynchronous suspension>
#3      FrontendCompiler.compile (package:frontend_server/frontend_server.dart:669:9)
<asynchronous suspension>
#4      starter (package:frontend_server/starter.dart:102:12)
<asynchronous suspension>
#5      main (file:///b/s/w/ir/x/w/sdk/pkg/frontend_server/bin/frontend_server_starter.dart:13:14)
<asynchronous suspension>

Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script '/home/myname/flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy' line: 1297

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/myname/flutter/bin/flutter'' finished with non-zero exit value 1
...

Strange thing: in line 8 of the mentioned file isn't even a reference to js_interop, but this code:

class ListPage extends StatefulWidget {
  const ListPage({super.key});

  @override
  State<ListPage> createState() => _ListPageState();
}

I already searched the internet and tried the following without success:

  • searching all files in the directory for the words 'js_interop', without result
  • flutter clean, then flutter pub get
  • removing newly installed extensions like CMake
  • restarting the VS Code and the PC

Here is the result of flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.9, on Linux Mint 21.1 5.15.0-88-generic, locale de_DE.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.83.1)
[✓] Connected device (2 available)
[✓] Network resources

• No issues found!

Can anybody help please?


Solution

  • The package dart:js_interop - just like dart:js - is only available when building for the web platform. Your code won't be able to run on Android.

    Somewhere in your project you include a dependency that itself depends on dart:js_interop.