SourceHorizon / logger

Small, easy to use and extensible logger which prints beautiful logs.
https://pub.dev/packages/logger
MIT License
197 stars 33 forks source link

Web issues #58

Closed busslina closed 6 months ago

busslina commented 7 months ago

When transpiling for Dart Web I got this warning, which is fatal because it breaks the transpile:

[WARNING] build_web_compilers:entrypoint on web/main.dart: Skipping compiling my_project|web/main.dart with dart2js because some of its
transitive libraries have sdk dependencies that are not supported on this platform:

logger|lib/src/outputs/file_output_stub.dart

https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-skipped-compiling-warnings

I tried to bypass it by replacing this:

import 'package:logger/logger.dart'

into this:

import 'package:logger/src/logger.dart';
import 'package:logger/src/filters/production_filter.dart';
import 'package:logger/src/outputs/console_output.dart';
import 'package:logger/src/printers/simple_printer.dart';
import 'package:logger/src/log_level.dart';

which leads to these static warnings (non-fatal), but the fatal warning still not solved:

Import of a library in the 'lib/src' directory of another package.
Try importing a public library that exports this library, or removing the import

Firstly I want to solve the fatal warning: Is there a way to import in a web safe way?

Secondly, would be great that the first solution also removes the non fatal warnings.

Thanks

Bungeefan commented 7 months ago

Hi, what a bummer... Sorry, this took me some time to research and understand your use-case and investigate possible solutions.

It seems that there are only two viable options for Dart Web projects:

I also tried modifying the stub to circumvent the pointless warning, but without using dynamic as type it seems to be impossible to satisfy the web compiler (using dynamic would also render the stub effectively impractical).

Interesting sidenote: The reason why this problem "only" exists in Dart and not in Flutter is because they made an (originally temporary) exception for Flutter Web. Source: https://github.com/dart-lang/build/issues/3614#issuecomment-1819457471