Flutter Web Compile Failed

I am trying to ‘flutter build web’ but it keep exiting abnormally. I am using Android Studio.

main.dart starting

import 'package:eye_vpn_lite_admin_panel/utils/app_constants.dart';
import 'package:eye_vpn_lite_admin_panel/view/screens/auth/login_screen.dart';
import 'package:eye_vpn_lite_admin_panel/view/screens/dashboard/dashboard_screen.dart';
import 'package:eye_vpn_lite_admin_panel/view/screens/server/add_server_screen.dart';
import 'package:eye_vpn_lite_admin_panel/view/screens/server/edit_server_screen.dart';
import 'package:flutter/material.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:get/get_navigation/src/routes/get_route.dart';
import 'package:get/get_navigation/src/routes/transitions_type.dart';
import 'package:url_strategy/url_strategy.dart';
import 'di_container.dart' as di;

pubspec.yaml dependencies

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  dio: ^4.0.6
  advanced_navigator: ^1.0.1
  lottie: ^2.6.0
  shared_preferences: ^2.2.1
  get: ^4.6.6
  get_it: ^7.6.4
  google_fonts: ^6.1.0
  url_strategy: ^0.2.0
  file_picker: ^5.5.0
  shimmer: ^3.0.0
  cached_network_image: ^3.3.0

Error

Target dart2js failed: ProcessException: Process exited abnormally:
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/utils/app_constants.dart'.
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/view/screens/auth/login_screen.dart'.
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/view/screens/dashboard/dashboard_screen.dart'.
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/view/screens/server/add_server_screen.dart'.
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/view/screens/server/edit_server_screen.dart'.
lib/main.dart:1:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/utils/app_constants.dart'
import 'package:eye_vpn_lite_admin_panel/utils/app_constants.dart';
       ^
lib/main.dart:2:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/view/screens/auth/login_screen.dart'
import 'package:eye_vpn_lite_admin_panel/view/screens/auth/login_screen.dart';
       ^
lib/main.dart:3:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/view/screens/dashboard/dashboard_screen.dart'
import 'package:eye_vpn_lite_admin_panel/view/screens/dashboard/dashboard_screen.dart';
       ^
lib/main.dart:4:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/view/screens/server/add_server_screen.dart'
import 'package:eye_vpn_lite_admin_panel/view/screens/server/add_server_screen.dart';
       ^
lib/main.dart:5:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/view/screens/server/edit_server_screen.dart'
import 'package:eye_vpn_lite_admin_panel/view/screens/server/edit_server_screen.dart';
       ^
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/controllers/add_server_controller.dart'.
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/controllers/auth_controller.dart'.
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/controllers/server_delete_controller.dart'.
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/controllers/update_admin_profile_controller.dart'.
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/data/repository/add_server_repo.dart'.
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/data/repository/server_update_repo.dart'.
lib/di_container.dart:8:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/utils/app_constants.dart'
import 'package:eye_vpn_lite_admin_panel/utils/app_constants.dart';
       ^
lib/di_container.dart:2:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/controllers/add_server_controller.dart'
import 'package:eye_vpn_lite_admin_panel/controllers/add_server_controller.dart';
       ^
lib/di_container.dart:3:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/controllers/auth_controller.dart'
import 'package:eye_vpn_lite_admin_panel/controllers/auth_controller.dart';
       ^
lib/di_container.dart:4:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/controllers/server_delete_controller.dart'
import 'package:eye_vpn_lite_admin_panel/controllers/server_delete_controller.dart';
       ^
lib/di_container.dart:5:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/controllers/update_admin_profile_controller.dart'
import 'package:eye_vpn_lite_admin_panel/controllers/update_admin_profile_controller.dart';
       ^
lib/di_container.dart:6:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/data/repository/add_server_repo.dart'
import 'package:eye_vpn_lite_admin_panel/data/repository/add_server_repo.dart';
       ^
lib/di_container.dart:7:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/data/repository/server_update_repo.dart'
import 'package:eye_vpn_lite_admin_panel/data/repository/server_update_repo.dart';
       ^
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/data/repository/admin_profile_repo.dart'.
lib/controllers/edit_server_controller.dart:1:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/data/repository/server_update_repo.dart'
import 'package:eye_vpn_lite_admin_panel/data/repository/server_update_repo.dart';
       ^
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/data/repository/server_details_repo.dart'.
Error: Couldn't resolve the package 'eye_vpn_lite_admin_panel' in 'package:eye_vpn_lite_admin_panel/data/repository/view_all_server_repo.dart'.
lib/data/repository/auth_repo.dart:2:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/utils/app_constants.dart'
import 'package:eye_vpn_lite_admin_panel/utils/app_constants.dart';
       ^
lib/controllers/admin_profile_controller.dart:2:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/data/repository/admin_profile_repo.dart'
import 'package:eye_vpn_lite_admin_panel/data/repository/admin_profile_repo.dart';
       ^
lib/controllers/server_details_controller.dart:2:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/data/repository/server_details_repo.dart'
import 'package:eye_vpn_lite_admin_panel/data/repository/server_details_repo.dart';
       ^
lib/controllers/view_all_server_controller.dart:1:8:
Error: Not found: 'package:eye_vpn_lite_admin_panel/data/repository/view_all_server_repo.dart'
import 'package:eye_vpn_lite_admin_panel/data/repository/view_all_server_repo.dart';
       ^
lib/controllers/admin_profile_controller.dart:12:9:
Error: Type 'AdminProfileRepo' not found.
  final AdminProfileRepo adminProfileRepo;
        ^^^^^^^^^^^^^^^^
lib/controllers/edit_server_controller.dart:17:9:
Error: Type 'ServerUpdateRepo' not found.
  final ServerUpdateRepo serverUpdateRepo;
        ^^^^^^^^^^^^^^^^
lib/controllers/server_details_controller.dart:12:9:
Error: Type 'ServerDetailsRepo' not found.
  final ServerDetailsRepo serverDetailsRepo;
        ^^^^^^^^^^^^^^^^^
lib/controllers/view_all_server_controller.dart:10:9:
Error: Type 'ViewAllServerRepo' not found.
  final ViewAllServerRepo viewAllServerRepo;
        ^^^^^^^^^^^^^^^^^
lib/main.dart:28:14:
Error: The getter 'AppConstants' isn't defined for the class 'MyApp'.
 - 'MyApp' is from 'package:remote_ip_vpn_admin_panel/main.dart' ('lib/main.dart').
      title: AppConstants.appName,
             ^^^^^^^^^^^^
lib/main.dart:33:21:
Error: The getter 'LoginScreen' isn't defined for the class 'MyApp'.
 - 'MyApp' is from 'package:remote_ip_vpn_admin_panel/main.dart' ('lib/main.dart').
      initialRoute: LoginScreen.routeName,
                    ^^^^^^^^^^^
lib/main.dart:35:23:
Error: The getter 'LoginScreen' isn't defined for the class 'MyApp'.
 - 'MyApp' is from 'package:remote_ip_vpn_admin_panel/main.dart' ('lib/main.dart').
        GetPage(name: LoginScreen.routeName, page: () => LoginScreen()),
                      ^^^^^^^^^^^
lib/main.dart:35:58:
Error: The method 'LoginScreen' isn't defined for the class 'MyApp'.
 - 'MyApp' is from 'package:remote_ip_vpn_admin_panel/main.dart' ('lib/main.dart').
        GetPage(name: LoginScreen.routeName, page: () => LoginScreen()),
                                                         ^^^^^^^^^^^
lib/main.dart:36:23:
Error: The getter 'DashboardScreen' isn't defined for the class 'MyApp'.
 - 'MyApp' is from 'package:remote_ip_vpn_admin_panel/main.dart' ('lib/main.dart').
        GetPage(name: DashboardScreen.routeName, page: () => DashboardScreen(), transition: Transition.fadeIn, transitionDuration: const Duration(milliseconds: 500)),
                      ^^^^^^^^^^^^^^^
lib/main.dart:36:62:
Error: The method 'DashboardScreen' isn't defined for the class 'MyApp'.
 - 'MyApp' is from 'package:remote_ip_vpn_admin_panel/main.dart' ('lib/main.dart').
        GetPage(name: DashboardScreen.routeName, page: () => DashboardScreen(), transition: Transition.fadeIn, transitionDuration: const Duration(milliseconds: 500)),
                                                             ^^^^^^^^^^^^^^^
lib/main.dart:37:23:
Error: The getter 'CreateServerScreen' isn't defined for the class 'MyApp'.
 - 'MyApp' is from 'package:remote_ip_vpn_admin_panel/main.dart' ('lib/main.dart').
        GetPage(name: CreateServerScreen.routeName, page: () => CreateServerScreen(), transition: Transition.fadeIn, transitionDuration: const Duration(milliseconds: 500)),
                      ^^^^^^^^^^^^^^^^^^
lib/main.dart:37:65:
Error: The method 'CreateServerScreen' isn't defined for the class 'MyApp'.
 - 'MyApp' is from 'package:remote_ip_vpn_admin_panel/main.dart' ('lib/main.dart').
        GetPage(name: CreateServerScreen.routeName, page: () => CreateServerScreen(), transition: Transition.fadeIn, transitionDuration: const Duration(milliseconds: 500)),
                                                                ^^^^^^^^^^^^^^^^^^
lib/main.dart:38:23:
Error: The getter 'EditServerScreen' isn't defined for the class 'MyApp'.
 - 'MyApp' is from 'package:remote_ip_vpn_admin_panel/main.dart' ('lib/main.dart').
        GetPage(name: EditServerScreen.routeName, page: () => EditServerScreen(), transition: Transition.fadeIn, transitionDuration: const Duration(milliseconds: 500)),
                      ^^^^^^^^^^^^^^^^
lib/main.dart:38:63:
Error: The method 'EditServerScreen' isn't defined for the class 'MyApp'.
 - 'MyApp' is from 'package:remote_ip_vpn_admin_panel/main.dart' ('lib/main.dart').
        GetPage(name: EditServerScreen.routeName, page: () => EditServerScreen(), transition: Transition.fadeIn, transitionDuration: const Duration(milliseconds: 500)),
                                                              ^^^^^^^^^^^^^^^^
lib/di_container.dart:31:44:
Error: Undefined name 'AppConstants'.
  sl.registerLazySingleton(() => DioClient(AppConstants.baseUrl, sl(), loggingInterceptor: sl(), sharedPreferences: sl()));
                                           ^^^^^^^^^^^^
lib/di_container.dart:35:34:
Error: Method not found: 'AddServerRepo'.
  sl.registerLazySingleton(() => AddServerRepo(dioClient: sl(), sharedPreferences: sl()));
                                 ^^^^^^^^^^^^^
lib/di_container.dart:40:34:
Error: Method not found: 'ServerUpdateRepo'.
  sl.registerLazySingleton(() => ServerUpdateRepo(dioClient: sl(), sharedPreferences: sl()));
                                 ^^^^^^^^^^^^^^^^
lib/di_container.dart:45:21:
Error: Method not found: 'AuthController'.
  Get.lazyPut(() => AuthController(dioClient: sl(), authRepo: sl()), fenix: true);
                    ^^^^^^^^^^^^^^
lib/di_container.dart:46:21:
Error: Method not found: 'AddServerController'.
  Get.lazyPut(() => AddServerController(dioClient: sl(), addServerRepo: sl()), fenix: true);
                    ^^^^^^^^^^^^^^^^^^^
lib/di_container.dart:49:21:
Error: Method not found: 'ServerDeleteController'.
  Get.lazyPut(() => ServerDeleteController(dioClient: sl(), serverDeleteRepo: sl()), fenix: true);
                    ^^^^^^^^^^^^^^^^^^^^^^
lib/di_container.dart:50:21:
Error: Method not found: 'UpdateAdminProfileController'.
  Get.lazyPut(() => UpdateAdminProfileController(dioClient: sl(), updateAdminProfileRepo: sl()), fenix: true);
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/controllers/admin_profile_controller.dart:12:9:
Error: 'AdminProfileRepo' isn't a type.
  final AdminProfileRepo adminProfileRepo;
        ^^^^^^^^^^^^^^^^
lib/controllers/edit_server_controller.dart:17:9:
Error: 'ServerUpdateRepo' isn't a type.
  final ServerUpdateRepo serverUpdateRepo;
        ^^^^^^^^^^^^^^^^
lib/controllers/server_details_controller.dart:12:9:
Error: 'ServerDetailsRepo' isn't a type.
  final ServerDetailsRepo serverDetailsRepo;
        ^^^^^^^^^^^^^^^^^
lib/controllers/view_all_server_controller.dart:10:9:
Error: 'ViewAllServerRepo' isn't a type.
  final ViewAllServerRepo viewAllServerRepo;
        ^^^^^^^^^^^^^^^^^
lib/data/repository/auth_repo.dart:20:9:
Error: The getter 'AppConstants' isn't defined for the class 'AuthRepo'.
 - 'AuthRepo' is from 'package:remote_ip_vpn_admin_panel/data/repository/auth_repo.dart' ('lib/data/repository/auth_repo.dart').
        AppConstants.loginUrl,
        ^^^^^^^^^^^^
lib/data/repository/auth_repo.dart:36:41:
Error: The getter 'AppConstants' isn't defined for the class 'AuthRepo'.
 - 'AuthRepo' is from 'package:remote_ip_vpn_admin_panel/data/repository/auth_repo.dart' ('lib/data/repository/auth_repo.dart').
      await sharedPreferences.setString(AppConstants.token, token);
                                        ^^^^^^^^^^^^
lib/data/repository/auth_repo.dart:38:47:
Error: The getter 'AppConstants' isn't defined for the class 'AuthRepo'.
 - 'AuthRepo' is from 'package:remote_ip_vpn_admin_panel/data/repository/auth_repo.dart' ('lib/data/repository/auth_repo.dart').
      print(await sharedPreferences.getString(AppConstants.token));
                                              ^^^^^^^^^^^^
lib/data/repository/auth_repo.dart:47:56:
Error: The getter 'AppConstants' isn't defined for the class 'AuthRepo'.
 - 'AuthRepo' is from 'package:remote_ip_vpn_admin_panel/data/repository/auth_repo.dart' ('lib/data/repository/auth_repo.dart').
    dioClient.updateHeader(sharedPreferences.getString(AppConstants.token) ?? "", "");
                                                       ^^^^^^^^^^^^
lib/data/repository/auth_repo.dart:48:40:
Error: The getter 'AppConstants' isn't defined for the class 'AuthRepo'.
 - 'AuthRepo' is from 'package:remote_ip_vpn_admin_panel/data/repository/auth_repo.dart' ('lib/data/repository/auth_repo.dart').
    return sharedPreferences.getString(AppConstants.token) ?? "";
                                       ^^^^^^^^^^^^
lib/data/repository/auth_repo.dart:54:37:
Error: The getter 'AppConstants' isn't defined for the class 'AuthRepo'.
 - 'AuthRepo' is from 'package:remote_ip_vpn_admin_panel/data/repository/auth_repo.dart' ('lib/data/repository/auth_repo.dart').
    return sharedPreferences.remove(AppConstants.token);
                                    ^^^^^^^^^^^^
lib/data/repository/auth_repo.dart:65:41:
Error: The getter 'AppConstants' isn't defined for the class 'AuthRepo'.
 - 'AuthRepo' is from 'package:remote_ip_vpn_admin_panel/data/repository/auth_repo.dart' ('lib/data/repository/auth_repo.dart').
      await sharedPreferences.setString(AppConstants.token, token);
                                        ^^^^^^^^^^^^
lib/data/repository/auth_repo.dart:73:40:
Error: The getter 'AppConstants' isn't defined for the class 'AuthRepo'.
 - 'AuthRepo' is from 'package:remote_ip_vpn_admin_panel/data/repository/auth_repo.dart' ('lib/data/repository/auth_repo.dart').
    return sharedPreferences.getString(AppConstants.token) ?? "";
                                       ^^^^^^^^^^^^
Error: Compilation failed.
  Command: C:\dev\flutter\bin\cache\dart-sdk\bin\dart.exe --disable-dart-dev C:\dev\flutter\bin\cache\dart-sdk\bin\snapshots\dart2js.dart.snapshot
  --platform-binaries=C:\dev\flutter\bin\cache\flutter_web_sdk\kernel --invoker=flutter_tool -Ddart.vm.product=true -DFLUTTER_WEB_AUTO_DETECT=true
  -DFLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/0545f8705df301877d787107bac1a6e9fc9ee1ad/ --native-null-assertions --no-source-maps -o
  C:\Users\brije\Downloads\EYE_VPN_LITE_SOURCE_CODE\EYE_VPN_LITE_SOURCE_CODE\eye_vpn_lite_admin_panel\.dart_tool\flutter_build\06edd3d07f0b028e0af881e89663c234\app.dill
  --packages=.dart_tool/package_config.json --cfe-only
  C:\Users\brije\Downloads\EYE_VPN_LITE_SOURCE_CODE\EYE_VPN_LITE_SOURCE_CODE\eye_vpn_lite_admin_panel\.dart_tool\flutter_build\06edd3d07f0b028e0af881e89663c234\main.dart
#0      RunResult.throwException (package:flutter_tools/src/base/process.dart:125:5)
#1      _DefaultProcessUtils.run (package:flutter_tools/src/base/process.dart:278:19)
<asynchronous suspension>
#2      Dart2JSTarget.build (package:flutter_tools/src/build_system/targets/web.dart:189:5)
<asynchronous suspension>
#3      _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:853:9)
<asynchronous suspension>
#4      Future.wait.<anonymous closure> (dart:async/future.dart:525:21)
<asynchronous suspension>
#5      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:791:32)
<asynchronous suspension>
#6      Future.wait.<anonymous closure> (dart:async/future.dart:525:21)
<asynchronous suspension>
#7      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:791:32)
<asynchronous suspension>
#8      FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:620:16)
<asynchronous suspension>
#9      WebBuilder.buildWeb (package:flutter_tools/src/web/compile.dart:89:34)
<asynchronous suspension>
#10     BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:198:5)
<asynchronous suspension>
#11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1297:27)
<asynchronous suspension>
#12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#13     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#14     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:339:9)
<asynchronous suspension>
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#16     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:285:5)
<asynchronous suspension>
#17     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:115:9)
<asynchronous suspension>
#18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#19     main (package:flutter_tools/executable.dart:90:3)
<asynchronous suspension>

Compiling lib\main.dart for the Web...                             27.9s
Exception: Failed to compile application for the Web.

I’m getting error even after following all the troubleshooting guides.

Quit and reopened Android Studio
Cross checked if my lib folder has all the packages I am trying to import
Ran flutter clean, flutter pub get. flutter pub cache clean.

I don’t know if it is the problem with the Android Studio itself.

Tried using flutter’s dart-sdk and custom dart-sdk both, thought maybe there was any problem with the dart-sdk, but still the same.

I tried this on both Mac and Windows 10, still the same thing.

  • Try updating with the Flutter version maybe it will help.

    – 

Leave a Comment