You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When compiling a simple flutter project in wasm using the latest dart stable version, the compiler will refuse building once a library that conditionally imports "dart:ffi" is imported and used.
This is a known issue and comes due to the fact that the library dart:ffi is actually available but we disallow importing it in newest versions (because we only have sketchy support for a subset of it atm - it's not generally working). It's not a specific issue to dart:ffi but also for dart:js / dart:js_util / ...
We could avoid this issue if we made it an internal library (i.e. dart:_ffi). Though this not so easy to do due to a few reasons (among them rolling such a change into flutter engine - which currently uses dart:ffi imports interop).
The conditional import mechanism works in the earlier stages than the backend mechanism that disallows importing certain (somewhat existing) libraries. We could investigate whether we can do that part earlier in the pipeline (/cc @osa1)
Using dart.library.js_interop is the condition we recommend for packages that work on web/js-environments.
I've made a few changes that will make us be able to evaluate the conditional import correctly (and thereby dart.library.ffi being false). Once cl/370580 lands and rolls up to flutter it should address these issues.
The fix for the conditional imports should be available in latest origin/main of flutter/flutter.
The fix was also cherry-picked onto Dart's stable channel and released under Dart SDK 3.4.4 yesterday.
It seems that flutter may not do hot fix releases on stable channel for 1-2 weeks, so it may take time until it arrives there.
So you can use versions of flutter before those if you really want to. But there's a reason we have disallowed it, so I can discourage relying on it until we have a properly working FFI for the web.
So you can use versions of flutter before those if you really want to. But there's a reason we have disallowed it, so I can discourage relying on it until we have a properly working FFI for the web.
I'm a bit lost.
I have updated dart to 3.4.4 and try to update my web project including flutter_svg package (using vector_graphics_compiler)
I get the following error:
../.pub-cache/hosted/pub.dev/vector_graphics_compiler-1.1.11+1/lib/src/svg/_tessellator_ffi.dart:6:1: Error: 'dart:ffi' can't be imported when compiling to Wasm.
import 'dart:ffi' as ffi;
^
../.pub-cache/hosted/pub.dev/vector_graphics_compiler-1.1.11+1/lib/src/svg/_path_ops_ffi.dart:6:1: Error: 'dart:ffi' can't be imported when compiling to Wasm.
import 'dart:ffi' as ffi;
^
../.pub-cache/hosted/pub.dev/vector_graphics_compiler-1.1.11+1/lib/src/svg/_tessellator_ffi.dart:6:1: Error:
'dart:ffi' can't be imported when compiling to Wasm.
import 'dart:ffi' as ffi;
What can I do to fix this issue ?
This particular issue in package:vector_graphics_compiler is due to a conditional import that was incorrectly evaluated in the compiler (see packages:vector_graphics_compiler/src/svg/tessellator.dart). The bug was fixed in 847c356 and should be available on flutter main/master channel. As mentioned above flutter may be slow atm to release new stable channel versions (which is why this fix isn't available there yet)
That being said, package:vector_graphics_compiler has other conditional imports (see e.g. package:vector_graphics_compiler/vector_graphics_compiler.dart) depending on dart.library.html (i.e. dart:html - the legacy API to talk to the DOM). We discourage usage of dart:html and instead want users to migrate to our new static JS interop APIs (and package:web which provides dom APIs using static interop). dart2wasm doesn't support dart:html - so this package would need to be migrated to static JS interop. Unfortunately the owner of this package is unavailable.
@mkustermann I try using 3.23.0-13.0.pre.337, but the issue still happen. I found the issue Error: 'dart:ffi' can't be imported when compiling to Wasm.. We need to improve the code for every package/plugin that we use?
But this issue fixed in 3.22.1
... @mkustermann I try using 3.23.0-13.0.pre.337, but the issue still happen. I found the issue Error: 'dart:ffi' can't be imported when compiling to Wasm.. We need to improve the code for every package/plugin that we use?
Activity
dcharkes commentedon Jun 10, 2024
cc @mkustermann @eyebrowsoffire @osa1
mkustermann commentedon Jun 10, 2024
This is a known issue and comes due to the fact that the library
dart:ffi
is actually available but we disallow importing it in newest versions (because we only have sketchy support for a subset of it atm - it's not generally working). It's not a specific issue todart:ffi
but also fordart:js
/dart:js_util
/ ...We could avoid this issue if we made it an internal library (i.e.
dart:_ffi
). Though this not so easy to do due to a few reasons (among them rolling such a change into flutter engine - which currently usesdart:ffi
imports interop).The conditional import mechanism works in the earlier stages than the backend mechanism that disallows importing certain (somewhat existing) libraries. We could investigate whether we can do that part earlier in the pipeline (/cc @osa1)
Using
dart.library.js_interop
is the condition we recommend for packages that work on web/js-environments.Use dart.library.html to distinguish dart2wasm from dart2js/ddc in co…
Use dart.library.html to distinguish dart2wasm from dart2js/ddc in co…
mkustermann commentedon Jun 10, 2024
I've made a few changes that will make us be able to evaluate the conditional import correctly (and thereby
dart.library.ffi
beingfalse
). Once cl/370580 lands and rolls up to flutter it should address these issues.[dart2wasm] Make `dart compile wasm` compiled apps disable `dart.libr…
dart compile wasm
compiled apps disabledart.library.ffi
#55979mkustermann commentedon Jun 11, 2024
The CL landed and will make it's way up to flutter main channel in the coming days.
In the meantime I've filed for a cherry-pick request to stable channel in Issue 55979
[stable] [dart2wasm] Make `dart compile wasm` compiled apps disable `…
mkustermann commentedon Jun 13, 2024
The fix for the conditional imports should be available in latest
origin/main
of flutter/flutter.The fix was also cherry-picked onto Dart's stable channel and released under
Dart SDK 3.4.4
yesterday.It seems that flutter may not do hot fix releases on stable channel for 1-2 weeks, so it may take time until it arrives there.
haorendashu commentedon Jun 17, 2024
@mkustermann Hello, can we rollback the local flutter version to avoid this issue? And whick version flutter can we rollback to?
mkustermann commentedon Jun 17, 2024
Due to incomplete and unstable ffi in dart2wasm we made two changes, here's the commits and how they rolled:
dart:ffi
(dbcf23a, engine: flutter/engine@b0f4d74, flutter/flutter@1dbf953)dart.library.ffi
(847c356, flutter/engine@6370add, flutter/flutter@cc24f87) (this issue)So you can use versions of flutter before those if you really want to. But there's a reason we have disallowed it, so I can discourage relying on it until we have a properly working FFI for the web.
fvisticot commentedon Jun 17, 2024
I'm a bit lost.
I have updated dart to 3.4.4 and try to update my web project including flutter_svg package (using vector_graphics_compiler)
I get the following error:
What can I do to fix this issue ?
nietsmmar commentedon Jun 17, 2024
@fvisticot
You have to build current flutter from git on your own. Or wait for the fix to be in the next version.
mkustermann commentedon Jun 17, 2024
This particular issue in
package:vector_graphics_compiler
is due to a conditional import that was incorrectly evaluated in the compiler (see packages:vector_graphics_compiler/src/svg/tessellator.dart). The bug was fixed in 847c356 and should be available on flutter main/master channel. As mentioned above flutter may be slow atm to release new stable channel versions (which is why this fix isn't available there yet)That being said,
package:vector_graphics_compiler
has other conditional imports (see e.g. package:vector_graphics_compiler/vector_graphics_compiler.dart) depending ondart.library.html
(i.e.dart:html
- the legacy API to talk to the DOM). We discourage usage ofdart:html
and instead want users to migrate to our new static JS interop APIs (andpackage:web
which provides dom APIs using static interop). dart2wasm doesn't supportdart:html
- so this package would need to be migrated to static JS interop. Unfortunately the owner of this package is unavailable.mkustermann commentedon Jun 17, 2024
/cc @kevmoo (see above)
kevmoo commentedon Jun 17, 2024
chandrabezzo commentedon Jun 26, 2024
@mkustermann I try using
3.23.0-13.0.pre.337
, but the issue still happen. I found the issueError: 'dart:ffi' can't be imported when compiling to Wasm.
. We need to improve the code for every package/plugin that we use?chandrabezzo commentedon Jun 26, 2024
But this issue fixed in 3.22.1
mkustermann commentedon Jun 26, 2024
Please see my response here: flutter/flutter#149984 (comment)
Locking this issue for more comments due to
package:flutter_svg
andpackage:vector_graphics_compiler
needs changes in those packages, which is tracked ffi imported when compiling for web wasm dnfield/vector_graphics#244