Flutter build fails on WSL2 with FileSystemException (OS Error: Cannot allocate memory, errno = 12)
I had the same error on WSL1 and it looks like a Dart runtime bug (not confirmed). I don't have a real solution but here is how I worked around:
Go to your Flutter installation directory.
Modify
packages/flutter_tools/lib/src/build_system/targets/assets.dart
as follows (convertFuture.wait(Iterable<Future>)
into a plain for loop):diff --git a/packages/flutter_tools/lib/src/build_system/targets/assets.dart b/packages/flutter_tools/lib/src/build_system/targets/assets.dartindex 83684e4455..b0bb340a79 100644--- a/packages/flutter_tools/lib/src/build_system/targets/assets.dart+++ b/packages/flutter_tools/lib/src/build_system/targets/assets.dart@@ -86,8 +86,7 @@ Future<Depfile> copyAssets(Environment environment, Directory outputDirectory, { kSkSLShaderBundlePath: skslBundle, };- await Future.wait<void>(- assetEntries.entries.map<Future<void>>((MapEntry<String, DevFSContent> entry) async {+ for (final MapEntry<String, DevFSContent> entry in assetEntries.entries) { final PoolResource resource = await pool.request(); try { // This will result in strange looking files, for example files with `/`@@ -115,7 +114,7 @@ Future<Depfile> copyAssets(Environment environment, Directory outputDirectory, { } finally { resource.release(); }- }));+ } // Copy deferred components assets only for release or profile builds. // The assets are included in assetBundle.entries as a normal asset when
Remove
bin/cache/flutter_tools.snapshot
to force the Flutter Tools snapshot to be re-generated.Try
flutter build
orflutter run
again.