FlutterToast icon indicating copy to clipboard operation
FlutterToast copied to clipboard

FlutterToast is running into error on upgrade to Flutter 3.10

Open applegrew opened this issue 1 year ago • 10 comments

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

applegrew avatar May 12 '23 15:05 applegrew

same here

rakib205 avatar May 13 '23 07:05 rakib205

I have the same issue

iliyami avatar May 13 '23 17:05 iliyami

Ditto

DamianB-BitFlipper avatar May 13 '23 18:05 DamianB-BitFlipper

@applegrew

rakib205 avatar May 13 '23 18:05 rakib205

same here

Mmisiek avatar May 14 '23 05:05 Mmisiek

Anyone managed to fix it ?

Mmisiek avatar May 14 '23 15:05 Mmisiek

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

shatanikmahanty avatar May 14 '23 18:05 shatanikmahanty

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.

applegrew avatar May 14 '23 18:05 applegrew

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 to typeof module && module && module.exports

  • Deploy to server and it will work. Or install npm install -g http-server and run npx http-server from build/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

shatanikmahanty avatar May 14 '23 19:05 shatanikmahanty

Same issue, Any solutions?

Aziz-cs avatar May 23 '23 08:05 Aziz-cs