Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flutter build web --wasm failed due to RangeError #596

Closed
teabuff opened this issue May 16, 2024 · 8 comments
Closed

flutter build web --wasm failed due to RangeError #596

teabuff opened this issue May 16, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@teabuff
Copy link

teabuff commented May 16, 2024

General

What bug do you experience? 🐞

I am using flutter_chat_ui in my app, and when I tried to run the flutter build web --wasm which was introduced recently
to build my web app in web assembly, I saw the following errors:

flutter build web --wasm

┌─ New feature ────────────────────────────────────────────────────────────────────────────┐
│   WebAssembly compilation is new. Understand the details before deploying to production. │
│   See https://flutter.dev/wasm for more information.                                     │
└──────────────────────────────────────────────────────────────────────────────────────────┘

Compiling lib/main.dart for the Web...
Invalid depfile: /home/user/workspace/tongsui_demo/.dart_tool/flutter_build/2bc6bf09fa388c3aa3580c6c6256f0e7/dart2wasm.d
Invalid depfile: /home/user/workspace/tongsui_demo/.dart_tool/flutter_build/2bc6bf09fa388c3aa3580c6c6256f0e7/dart2wasm.d
Target dart2wasm failed: ProcessException: Process exited abnormally with exit code 64:
*NOTE*: Compilation to WasmGC is experimental.
The support may change, or be removed, with no advance notice.

Exception in InstanceInvocation at file:///home/user/.pub-cache/hosted/pub.dev/flutter_chat_ui-1.6.12/lib/src/widgets/typing_indicator.dart:244:53

Unhandled exception:
RangeError (index): Invalid value: Valid value range is empty: 1
#0      List.[] (dart:core-patch/growable_array.dart:264)
#1      Intrinsifier.generateInstanceIntrinsic (package:dart2wasm/intrinsics.dart:337)
#2      CodeGenerator.visitInstanceInvocation (package:dart2wasm/code_generator.dart:1817)
#3      InstanceInvocation.accept1 (package:kernel/ast.dart:5803)

What behavior is expected? 💡

flutter build web --wasm should be run successfully


Environment info

Please specify the flutter, flutter-chat-ui versions.

flutter: 3.22
flutter-chat-ui: 1.6.12


Platform

Device (e.g. Android emulator, iOS simulator, Samsung Galaxy S21): Chrome 124.0.6367.208

OS version (e.g. iOS 14.5, Android 11): Mac os 14.4.1


Additional context

I think the issue is src/widgets/typing_indicator.dart:244 use author[1] that does not compatible with the wasm requirement.

I modified the code to

    else if (author.length == 2) {
      return '${author.first.firstName} and ${author.last.firstName}';
    }

that fixed the issue and flutter build web --wasm is successful after the change. If you are OK with this method (replace author[1] to author.last), I can create a pull request for it.

@teabuff teabuff added the bug Something isn't working label May 16, 2024
@demchenkoalex
Copy link
Member

I will check it and release this week. Thanks for raising this!

@demchenkoalex
Copy link
Member

yeah this change works and build passes! please note that in the example project I had to remove all dependencies that use ffi cause it crashes with some random error. But I guess you already know that. Change will be included in v1.6.13 release that I will do today or tomorrow morning.

@Rexios80
Copy link

I don't see any issue with the code that is failing to compile. Is this a bug in the WASM compiler?

@demchenkoalex
Copy link
Member

yes, it is the same issue as here rive-app/rive-flutter#391, because rive also depends on ffi

@osa1
Copy link

osa1 commented May 23, 2024

please note that in the example project I had to remove all dependencies that use ffi cause it crashes with some random error

@demchenkoalex could you commit your changes that remove these dependencies so that I can take a look at the crash reported in the OP and debug?

@mkustermann
Copy link

Let's track this issue on the Dart SDK issue tracker (see dart-lang/sdk#55817)

@demchenkoalex
Copy link
Member

hey @osa1 sorry for the late reply.

pushed a branch called wasm-error.

in the example folder you can run flutter build web --wasm and it will fail with the original issue. To fix the issue go to the lib/src/widgets/typing_indicator.dart line 245 and change author[1].firstName to author.last.firstName. Prior to this line there is a check that author.length == 2 so there are 2 items always, and they should be accessible by both [0] and [1] indices and first and last properties

@osa1
Copy link

osa1 commented May 30, 2024

Thanks @demchenkoalex. This was fixed by dart-lang/sdk#55817.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants