Not a compile-time constant. | const _AlwaysThrows alwaysThrows = _AlwaysThrows();

Issue

I’ve inherited a Dart project that has been dormant for about 3 years. When trying to compile the project I get an error from the meta package. I am unsure how to resolve it.

The error is:

[Error from Dart2JS on askbayoucom|web/main.dart]:
web\packages\meta\meta.dart:50:36:
Not a compile-time constant.
const _AlwaysThrows alwaysThrows = _AlwaysThrows();
                                   ^^^^^^^^^^^^^^^

I’m using SDK 1.24.3 which I believe is the most recent allowable due to this entry in pubspec.yaml

environment:
  sdk: '>=1.0.0 <2.0.0'

When running pub upgrade I get the output:

Resolving dependencies...
  args 1.5.1 (1.6.0 available)
  async 1.13.3 (2.4.2 available)
  barback 0.15.2+15 (0.15.2+16 available)
  browser 0.10.0+3
  charcode 1.1.2 (1.1.3 available)
  collection 1.14.6 (1.14.13 available)
  csslib 0.14.3 (0.16.2 available)
  dart_config 0.5.0
  dart_to_js_script_rewriter 1.0.3
  html 0.13.3 (0.14.0+3 available)
  js 0.6.1+1 (0.6.2 available)
  logging 0.11.3+2 (0.11.4 available)
  meta 1.2.2 (1.3.0-nullsafety.2 available)
  path 1.5.1 (1.7.0 available)
  pool 1.3.4 (1.4.0 available)
  source_span 1.5.5 (1.7.0 available)
  stack_trace 1.9.3 (1.9.5 available)
  string_scanner 1.0.4 (1.0.5 available)
  term_glyph 1.1.0 (1.2.0-nullsafety available)
  unittest 0.11.7 (0.12.4+1 available)
  utf 0.9.0+3 (0.9.0+5 available)
  yaml 2.1.13 (2.2.1 available)
No dependencies changed.

Solution

That’s a bug in the SDK requirements of package meta.
The const _AlwaysThrows alwaysThrows = _AlwaysThrows(); requires a v2.0.0 or later SDK, but the SDK requirement for that meta package incorrectly claims that it works for earlier SDK versions.

See https://github.com/dart-lang/sdk/issues/42935

Answered By – lrn

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *