FlutterToast
FlutterToast copied to clipboard
FlutterToast is running into error on upgrade to Flutter 3.10
Using this library gives error "Toastify" does not exist.
When it loads for the first time I see the following JS error.
caught TypeError: Cannot read properties of null (reading 'exports')
at toastify.js:14:48
The reason is the code inside toastify.js
"object" == typeof module && module.exports ? module.exports = o() : t.Toastify = o()
Not sure what was the scenario before but in Flutter 3.10 module
is coming as null
and null
is object
so the "object" == typeof module
check passes and it proceeds to module.exports
, which naturally fails and Toastify
remains undefined.
Maybe before Flutter 3.10 module
was undefined
?
I am using fluttertoast 8.2.1
same here
I have the same issue
Ditto
@applegrew
same here
Anyone managed to fix it ?
I found this difference.
Before flutter 3.10:
"object" == typeof module in js console chrome debugger returned false
But in 3.10 it returns true.
So in previous versions module.exports was never called
I found this difference.
Before flutter 3.10:
"object" == typeof module in js console chrome debugger returned false
But in 3.10 it returns true.
So in previous versions module.exports was never called
Yes because before module
was undefined
but now some code is setting it to null
.
I am using this as a temporary fix.
-
flutter build web --release
(You may use debug to test in debug env) -
Navigate to
build/web/assets/packages/fluttertoast/assets/toastify.js
-
Change
typeof module && module.exports
totypeof module && module && module.exports
-
Deploy to server and it will work. Or install
npm install -g http-server
and runnpx http-server
frombuild/web
to see changes in local
This is not a permanent fix but atleast keeps your production from not working. You need to change it every time as running flutter build will remove the changes
Same issue, Any solutions?