-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[web] [DDC] TypeError: Cannot read properties of undefined (reading 'new') #56498
Comments
Summary: The issue is a |
@Rexios80 Do you have any clues what is going on here? 🤔 |
What dart/flutter version? There might be some fixes that still aren't merged into stable. |
@Rexios80 im faced this:
|
Can you reproduce on flutter master? |
This also happens on master |
Is it the cascade that's causing the issue? |
Nope. Removing it doesn't help. |
You say this is a workaround: HttpClientAdapter makeHttpClientAdapter() {
final adapter = HttpClientAdapter() as BrowserHttpClientAdapter;
adapter.withCredentials = true;
return adapter;
} What about this fixes the issue if it's not removing the cascade? Is it the cast? |
Yes, creating the adapter like this and force cast it does work, it's not about the cascade. The workaround is to help people to achieve their goal. |
Which of the web environments are you experiencing this issue?
|
The DDC compiler. The built Web application does not run into the issue. |
I actually have this error in one of my projects now. Not sure how it took me this long to notice. The workaround provided by @AlexV525 does fix the issue. |
This is getting worse according to cfug/dio#2282 (comment) @nshahan @sigmundch Would you mind taking further investigations? |
I'm getting this error using: Flutter 3.29.0 • channel stable • https://github.com/flutter/flutter.git I'm not even using conditional imports or anything. Simply trying to use BrowserHttpClientAdapter() at all throws this error. |
I have a fix in progress but to summarize the issue: DDC compiles libraries modularly but it can sometimes combine libraries from different packages into the same JS module. In this case both The workaround to use |
The attached bug shows an issue users have been encountering where a constructor seems to be undefined. It turns out this is because DDC is trying to read the constructor from the wrong library. This is happening because both 'package:dio' and a sister package 'package:dio_web_adapter' both contain a library with the same path: 'src/adapter.dart'. 'BrowserHttpClientAdapter' the class they are trying to reference is defined in 'package:dio/src/adapter.dart'. However, due to a naming collision, their import is referencing 'package:dio_web_adapter/src/adapter.dart'. This naming collision happens because of the logic in '_jsLibraryAlias'. By truncating the start of the import URI (i.e. 'dio/' and 'dio_web_adapter/') the two libraries map to the same alias. This alias is then used to as the key in the AMD module export object and since both libraries are in the same module, only the second one gets exported. This code may have been written with the assumption that libraries from different packages would always be in different modules (in which case the shortened paths shouldn't collide) but this is not the case. The fix is to use the full import URI including the package name. In writing the attached modular test I discovered another issue that only affects es6 imports. The ScopedId resolver was not considering NameSpecifier as a declaration point for variables. This lead to a similar name collision since the import alias's name was also being derived from a truncated import URI. In the test, both 'f1/foo.dart' and 'f2/foo.dart' were being imported 'as foo'. Now one is 'as foo' and the other is 'as foo$'. The first issue affects both AMD and es6 while the second issue only affects es6. The modular tests run with es6 so the new test fails if either of these fixes is not in place. The new DDC module system is not affected by either issue since it doesn't use NameSpecifiers and it uses the full import URI as a string to register libraries rather than a shortened alias. Tested on TGP and with a local Flutter application. Bug: #56498 Change-Id: I5bdb945cfbe615874b40e2fc4ebba31b661cf3b7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410260 Reviewed-by: Nicholas Shahan <nshahan@google.com> Commit-Queue: Nate Biggs <natebiggs@google.com>
This tracker is for issues related to:
We've split our Dio adapter with conditional imports. However, writing the caller in a specific way does not reference the correct constructor as I can tell.
Consider the example, running this on Flutter Web environment will unexpectedly throw
TypeError: Cannot read properties of undefined (reading 'new')
:main.dart
adapter.dart
adapter_io.dart
adapter_web.dart
Workaround
The text was updated successfully, but these errors were encountered: