spebbe / dartz

Functional programming in Dart
MIT License
749 stars 60 forks source link

Flutter Web Target dart2js failed #31

Closed Kiruel closed 4 years ago

Kiruel commented 4 years ago

Hi, I try to use dartz for flutter web with this command: flutter run -d chrome --release -t lib/main_dev.dart -v

But I get this error:

[   +3 ms] Target dart2js failed: Exception: lib/features/auth/data/repositories/token_repostitory_impl.dart:30:34:
           Error: The return type of the method 'TokenRepositoryImpl.getTokenLocal' is 'Future<Either<Failure/*1*/,
Token/*1*/>>',
           which does not match the return type, 'Future<Either<Failure/*2*/, Token/*2*/>>', of the overridden method,
           'TokenRepository.getTokenLocal'.
            - 'Future' is from 'dart:async'.
            - 'Either' is from 'package:dartz/dartz.dart'
            ('../../../.pub-cache/hosted/pub.dartlang.org/dartz-0.8.9/lib/dartz.dart').
            - 'Failure/*1*/' is from 'lib/core/errors/failures.dart'.
            - 'Token/*1*/' is from 'lib/features/auth/domain/entities/token.dart'.
            - 'Failure/*2*/' is from 'package:app/core/errors/failures.dart'
('lib/core/errors/failures.dart').
            - 'Token/*2*/' is from 'package:app/features/auth/domain/entities/token.dart'
            ('lib/features/auth/domain/entities/token.dart').
             Future<Either<Failure, Token>> getTokenLocal() async {
                                            ^
           lib/features/auth/domain/repositories/token_repository.dart:7:34:
           Info: This is the overridden method ('getTokenLocal').
             Future<Either<Failure, Token>> getTokenLocal();
                                            ^
           lib/features/auth/data/repositories/token_repostitory_impl.dart:19:34:
           Error: The return type of the method 'TokenRepositoryImpl.getTokenGoogle' is 'Future<Either<Failure/*1*/,
           Token/*1*/>>', which does not match the return type, 'Future<Either<Failure/*2*/, Token/*2*/>>', of the
overridden
           method, 'TokenRepository.getTokenGoogle'.
            - 'Future' is from 'dart:async'.
            - 'Either' is from 'package:dartz/dartz.dart'
            ('../../../.pub-cache/hosted/pub.dartlang.org/dartz-0.8.9/lib/dartz.dart').
            - 'Failure/*1*/' is from 'lib/core/errors/failures.dart'.
            - 'Token/*1*/' is from 'lib/features/auth/domain/entities/token.dart'.
            - 'Failure/*2*/' is from 'package:app/core/errors/failures.dart'
('lib/core/errors/failures.dart').
            - 'Token/*2*/' is from 'package:app/features/auth/domain/entities/token.dart'
            ('lib/features/auth/domain/entities/token.dart').
             Future<Either<Failure, Token>> getTokenGoogle(String accessToken) async {
                                            ^
           lib/features/auth/domain/repositories/token_repository.dart:6:34:
           Info: This is the overridden method ('getTokenGoogle').
             Future<Either<Failure, Token>> getTokenGoogle(String accessToken);
                                            ^
           lib/features/auth/data/repositories/token_repostitory_impl.dart:23:20:
           Error: The argument type 'TokenModel' can't be assigned to the parameter type 'Token'.
            - 'TokenModel' is from 'package:app/features/auth/data/models/token_model.dart'
            ('lib/features/auth/data/models/token_model.dart').
            - 'Token' is from 'lib/features/auth/domain/entities/token.dart'.
                 return Right(result);
                              ^
           lib/features/auth/data/repositories/token_repostitory_impl.dart:33:20:
           Error: The argument type 'TokenModel' can't be assigned to the parameter type 'Token'.
            - 'TokenModel' is from 'package:app/features/auth/data/models/token_model.dart'
            ('lib/features/auth/data/models/token_model.dart').
            - 'Token' is from 'lib/features/auth/domain/entities/token.dart'.
                 return Right(result);
                              ^
           Error: Compilation failed.

[  +13 ms] Compiling lib/main_dev.dart for the Web... (completed in 4.9s)
[   +1 ms] Building application for the web... (completed in 5.0s)
[   +1 ms] "flutter run" took 7,012ms.
Exception: Failed to compile application for the Web.

#0      throwToolExit (package:flutter_tools/src/base/common.dart:28:3)
#1      buildWeb (package:flutter_tools/src/web/compile.dart:66:5)
<asynchronous suspension>
#2      WebFs.start (package:flutter_tools/src/build_runner/web_fs.dart:308:13)
<asynchronous suspension>
#3      _DwdsResidentWebRunner.run.<anonymous closure>
(package:flutter_tools/src/build_runner/resident_web_runner.dart:602:36)
#4      asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:32)
#5      _rootRun (dart:async/zone.dart:1126:13)
#6      _CustomZone.run (dart:async/zone.dart:1023:19)
#7      _runZoned (dart:async/zone.dart:1518:10)
#8      runZoned (dart:async/zone.dart:1502:12)
#9      asyncGuard (package:flutter_tools/src/base/async_guard.dart:109:3)
#10     _DwdsResidentWebRunner.run (package:flutter_tools/src/build_runner/resident_web_runner.dart:601:32)
<asynchronous suspension>
#11     RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:505:37)
<asynchronous suspension>
#12     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:620:18)
#13     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:74:64)
#14     _rootRunUnary (dart:async/zone.dart:1134:38)
#15     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#16     _FutureListener.handleValue (dart:async/future_impl.dart:140:18)
#17     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#18     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#19     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#20     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:33:15)
#21     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:291:13)
#22     RunCommand.usageValues (package:flutter_tools/src/commands/run.dart)
#23     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:74:64)
#24     _rootRunUnary (dart:async/zone.dart:1134:38)
#25     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#26     _FutureListener.handleValue (dart:async/future_impl.dart:140:18)
#27     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#28     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#29     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#30     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:33:15)
#31     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:291:13)
#32     IosProject.isSwift (package:flutter_tools/src/project.dart)
#33     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:74:64)
#34     _rootRunUnary (dart:async/zone.dart:1134:38)
#35     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#36     _FutureListener.handleValue (dart:async/future_impl.dart:140:18)
#37     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#38     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#39     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#40     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:33:15)
#41     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:291:13)
#42     IosProject.buildSettings (package:flutter_tools/src/project.dart)
#43     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:74:64)
#44     _rootRunUnary (dart:async/zone.dart:1134:38)
#45     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#46     _FutureListener.handleValue (dart:async/future_impl.dart:140:18)
#47     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#48     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#49     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#50     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:33:15)
#51     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:291:13)
#52     XcodeProjectInterpreter.getBuildSettings (package:flutter_tools/src/ios/xcodeproj.dart)
#53     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:74:64)
#54     _rootRunUnary (dart:async/zone.dart:1134:38)
#55     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#56     _FutureListener.handleValue (dart:async/future_impl.dart:140:18)
#57     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#58     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#59     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#60     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:33:15)
#61     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:291:13)
#62     _DefaultProcessUtils.run (package:flutter_tools/src/base/process.dart)
#63     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:74:64)
#64     _rootRunUnary (dart:async/zone.dart:1134:38)
#65     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#66     _FutureListener.handleValue (dart:async/future_impl.dart:140:18)
#67     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#68     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#69     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#70     Future.wait.<anonymous closure> (dart:async/future.dart:400:22)
#71     _rootRunUnary (dart:async/zone.dart:1134:38)
#72     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#73     _FutureListener.handleValue (dart:async/future_impl.dart:140:18)
#74     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#75     Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#76     Future._complete (dart:async/future_impl.dart:516:7)
#77     _BufferingStreamSubscription.asFuture.<anonymous closure> (dart:async/stream_impl.dart:206:14)
#78     _rootRun (dart:async/zone.dart:1122:38)
#79     _CustomZone.run (dart:async/zone.dart:1023:19)
#80     _CustomZone.runGuarded (dart:async/zone.dart:925:7)
#81     _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:391:13)
#82     _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:401:15)
#83     _BufferingStreamSubscription._close (dart:async/stream_impl.dart:285:7)
#84     _SinkTransformerStreamSubscription._close (dart:async/stream_transformers.dart:98:11)
#85     _EventSinkWrapper.close (dart:async/stream_transformers.dart:25:11)
#86     _StringAdapterSink.close (dart:convert/string_conversion.dart:251:11)
#87     _Utf8ConversionSink.close (dart:convert/string_conversion.dart:302:20)
#88     _ConverterStreamEventSink.close (dart:convert/chunked_conversion.dart:82:18)
#89     _SinkTransformerStreamSubscription._handleDone (dart:async/stream_transformers.dart:143:24)
#90     _rootRun (dart:async/zone.dart:1122:38)
#91     _CustomZone.run (dart:async/zone.dart:1023:19)
#92     _CustomZone.runGuarded (dart:async/zone.dart:925:7)
#93     _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:391:13)
#94     _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:401:15)
#95     _BufferingStreamSubscription._close (dart:async/stream_impl.dart:285:7)
#96     _SyncStreamControllerDispatch._sendDone (dart:async/stream_controller.dart:774:19)
#97     _StreamController._closeUnchecked (dart:async/stream_controller.dart:631:7)
#98     _StreamController.close (dart:async/stream_controller.dart:624:5)
#99     _Socket._onData (dart:io-patch/socket_patch.dart:1838:21)
#100    _rootRunUnary (dart:async/zone.dart:1138:13)
#101    _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#102    _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
#103    _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:338:11)
#104    _BufferingStreamSubscription._add (dart:async/stream_impl.dart:265:7)
#105    _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:766:19)
#106    _StreamController._add (dart:async/stream_controller.dart:642:7)
#107    _StreamController.add (dart:async/stream_controller.dart:588:5)
#108    new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1386:35)
#109    _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:892:18)
#110    _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#111    _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#112    _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#113    _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:175:5)

When I compile for Android or iOS there are no error only for web, can you help me on that ?

Flutter doctor

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.12.16-pre.33, on Mac OS X 10.15.1 19B88, locale en-FR)

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.40.1)
[✓] Connected device (3 available)

! Doctor found issues in 1 category.

Dartz version

dartz: ^0.8.9

spebbe commented 4 years ago

Not trying to be rude, but nothing in the stack trace hints at this being related to dartz -- how did you come to that conclusion? It clearly states that Token and Failure have conflicting definitions, probably because you are mixing package relative and file relative imports.

Kiruel commented 4 years ago

Ok you are right nothing from dartz its from dart2js, when I use package:app/features/auth/domain/entities/token.dart it make this error so I change for local path like this for example ../entities/token.dart.

spebbe commented 4 years ago

Great -- glad that it worked out!