Reputation: 272
Im trying to build flutter web app on release mode using flutter build web
(also tried flutter build web --no-sound-null-safety
).When i do,im getting the below error.
D:\saves\reset_password>flutter build web
Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead.
.dart_tool/flutter_build/1916f9367c0e6ad6c929bd88cf5227e5/web_plugin_registrant.dart:14:38:
Error: Null safety features are disabled for this library.
void registerPlugins([final Registrar? pluginRegistrar]) {
^
Error: Compilation failed.
Compiling lib\main.dart for the Web... 44.9s
Exception: Failed to compile application for the Web.
It works fine when i run it directly in debug mode using flutter run
.
Note: I recently upgraded to flutter 3.0 and im using Android studio.
Below is my flutter doctor
( i am aware of the android tools missing.since im building for web,i didnt pay much attention to it)
D:\saves\reset_password>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 3.1.0-0.0.pre.966, on Microsoft Windows [Version 10.0.19044.1706], locale en-IN)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
X cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
X Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.5)
[√] Android Studio (version 4.1)
[√] VS Code (version 1.66.2)
[√] Connected device (3 available)
[√] HTTP Host Availability
! Doctor found issues in 1 category.
Upvotes: 18
Views: 18155
Reputation: 1
Should you encounter a similar issue to mine, it's worth checking whether your terminal in Android Studio is configured with the correct path. In my case, the terminal was directed to one of my previous projects. Simply restarting the terminal or navigating to the correct directory ('cd' command) resolved the problem
Upvotes: 0
Reputation: 849
in case you're using old version of flutter, it's probably because old dependency
you can run this to upgrade dependencies that still works in your flutter version
flutter pub upgrade --major-versions
Upvotes: 1
Reputation: 115
You can try to update the dependency that is giving the error
Upvotes: 0
Reputation: 149
Delete /flutter/bin/cache
folder.
Run flutter doctor
.
Then, run flutter clean
, flutter pub get
and flutter build web
.
Upvotes: 2
Reputation: 648
For me was launching flutter clean && flutter pub get
on the cmd/terminal, the solution.
Upvotes: 13
Reputation: 385
The fix for this issue is now available on the stable channel 3.3.0. It was due to a change in one of the 3.0 builds that put null safe features in the web plugins registrant. Any web project without null safety would have been affected.
Upvotes: 0
Reputation: 361
I had a similar problem. It was on server based on Ubuntu.
In my case I had:
Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead. flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-3.3.19/lib/firebase_auth_web.dart:402:16: Error: The method 'FirebaseAuthWeb.verifyPhoneNumber' has fewer named arguments than those of overridden method 'FirebaseAuthPlatform.verifyPhoneNumber'. ...
I discovered that a firebase_auth_web dependency had a deprecated version and wasn't used in the project. Hence I removed this dependency. After that the problem disappears.
Upvotes: 1
Reputation: 55
flutter build web
worked on my local but not on my server, after sudo reboot
it worked again. the above sugestet answer didnt work for me...
Upvotes: 0
Reputation: 272
I fixed this error by myself.Here's what i did:
I found that there are few dependencies in pubspec.yaml
file that are not used currently.I navigated to my .dart_tool\flutter_build\cb8031cdd1bfbcb95122aae4ad9a63d5\web_plugin_registrant.dart
and found that those dependencies are being referenced inside registerPlugins()
.
I cleared all those unused dependencies shown in registerPlugins()
and did the following steps:
1.flutter pub get
2.flutter clean
3.flutter build web
And VIOLA! The error went away and i got my files in the build\web
folder.
Upvotes: -3