"Error: The type 'JSObject' can't be used as supertype." while deploying flutter app to vercel
Asked Answered
W

6

15

Getting Error: The type 'JSObject' can't be used as supertype. error but I havent used dart.js anywhere in my code and unable to deploy my app to vercel.

enter image description here

below is my pubspec:

name: appname
description: "A new Flutter project."
publish_to: 'none'
version: 0.1.0

environment:
  sdk: '>=3.2.5 <4.0.0'

dependencies:
  flutter:
    sdk: flutter
  get: ^4.6.6
  font_awesome_flutter: ^10.6.0
  http: ^1.2.0
  flutter_dotenv: ^5.1.0
  

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

assets:
  - .env
Wraith answered 6/2 at 12:10 Comment(1)
Can you include your pubspec?Bolt
U
32

I had this same issue, not sure what packages caused the issue, but running a

flutter pub upgrade

moved quite a few packages forward for my project and fixed the issue.

I suspect the package makers I rely on have updated their transitive dependencies. Give that a try before doing any dependency overrides.

If it is still causing an issue, you can force transitive depencies forward with:

dependency_overrides:
  web: ^0.4.0

This was on the stable Flutter channel, no need to swap to beta

Unicorn answered 16/2 at 16:34 Comment(1)
hey thanks,it worked for me. could you provide any resources on how this fixes the issue? why this is caused?Jerrold
B
7

For me, it was as simple as running

flutter pub add web:^0.5.0

My web dependency was stuck at 0.3.0 as a transitive dependency. The above command updates it to the latest version by turning it into a direct dependency.

Biddie answered 18/2 at 9:31 Comment(0)
B
4

The update 0.4.0 of web has already addressed the issues shown in the error. From the changelog:

Remove implements JSObject from all types.

For example, the class definition for ReadableStream in 0.3.0 was:

class ReadableStream implements JSObject {

It is now has changed to:

class ReadableStream {

The http package depends on the web package. In the version 1.2.0 of http, it depends on web with this version constraint:

web: '>=0.3.0 <0.5.0'

To fix the issue, simply depends the web package directly in your pubscpec. It is safe to use version 0.4.0 and above since it still meet the constraints shown above.

In your pubspec file:

dependencies:
  web: ^0.4.0

Now another problem arises, the flutter_test package may not be compatible with these changes. If you're not using flutter_test, you can simply remove it from the dev_dependencies. If you're using it, you can try upgrading the Flutter SDK to the version that has flutter_test supports web ≥ 0.4.0.

Bolt answered 7/2 at 9:47 Comment(0)
P
4

I faced the same issue with the flutter build web and flutter runcommands.
Like most of the people here said, it was due to the dependency with an older version of web.

Got solved by flutter pub upgrade.

Pseudohemophilia answered 28/2 at 5:50 Comment(0)
C
1

same for me. running pub upgrade did the trick. I think it has to do with some sort of forced dependency in the latest flutter version.

Calcite answered 26/2 at 16:41 Comment(0)
S
0

I was able to get pass this issue. Here's my steps:

Switch to beta channel

flutter channel beta

Upgrade SDK

flutter upgrade

Upgrade dependencies

flutter pub upgrade

Deploy to vercel and issue should go away

Looking forward on web: ^0.4.2 support in #flutter stable channel

Thanks @Dhafin Rayhan

Hope it helps

Sile answered 10/2 at 9:21 Comment(1)
is there a way to integrate Vercel Environmental variable with flutter appWraith

© 2022 - 2024 — McMap. All rights reserved.