-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to fix compilation errors when not building for web? #317
Comments
Can you elaborate? Are you using a stub there to avoid the unsupported error? |
If I import dart:io, to use I'm not very familiar with all this: I've just stumbled upon this kind of problem recently. So if you tell me there's no way to import web/web without going the stub way, that's fine. |
@srujzs I am having the exact same issue. Even though my code logic is wrapped around
it causes my project to stop compiling to native platform targets. Just like @gdurandrexel suggested, the solution in this case was to create a stub file and add a conditional import.
I would be really nice to have this stub file created inside the package so it doesn't affect native platform targets or maybe just add this info to the package's home page, just in case someone else has the same problem. |
I may be wrong, but I think you only need two stubs - one for the VM and one for web and then just do a conditional like you were thinking of for import 'vm_impl.dart' as impl
if (dart.library.js_interop) 'web_impl.dart';
Ultimately if you want to avoid creating your own more general stubs and want to still use
It's a good idea to put this in the README or an FAQ. I'm not completely opposed to a stub of Similar issue: #55 |
package:web
be provided?
package:web
be provided?
Yes, you're right, I need only 2 files as you explained. I had come across several examples with another stub file and at that time I was still in my copy/paste phase regarding this new kind of problem. Yes, a full stub of web/web may work, and I proposed this solution because the code is generated, so it might not be too much work or need too much maintenance (though it may, I have no idea). There would still be the problem of dart:js_interop that surfaces in the API. If we cannot apply the same technique for this package also, then there is no point in creating a stub for web/web I suppose. |
Agreed. We may be able to get away with typedefs, but I'm not sure. We definitely do not want to either do a huge breaking change to |
Is there a way to override |
Nope. |
@kevmoo I mean that we could use it to provide paths to the patched |
you can override |
I have a flutter app that should support mobile and web, but compilation fails when building for mobile with errors such as "Dart library 'dart:js_interop' is not available on this platform.".
In my code I import dart:io and web/web and use kIsWeb to call IO methods or web methods.
When compiling for web, importing dart:io does not cause any problem.
I've read about creating a stub file and importing io or web implementations, but my code is sprinkled with kIsWeb checks with tiny bits of code.
Is it really the only way to make this work? How come importing dart:io is fine but web/web is not?
Could this package provide a stub so we can write something like this:
The text was updated successfully, but these errors were encountered: