Skip to content
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

Getting null safety errors despite not opting-in #44648

Open
jimmyff opened this issue Jan 12, 2021 · 13 comments
Open

Getting null safety errors despite not opting-in #44648

jimmyff opened this issue Jan 12, 2021 · 13 comments
Labels
area-build Use area-build for SDK build issues.

Comments

@jimmyff
Copy link

jimmyff commented Jan 12, 2021

I'm trying to use build runner but all of a sudden it's throwing me null safety errors:

flutter pub run build_runner watch --delete-conflicting-outputs 

Fails with:

Failed to precompile build_runner:build_runner:
../../sdks/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-1.9.0/bin/build_runner.dart:89:9: Warning: Operand of null-aware operation '?.' has type 'StreamSubscription<dynamic>' which excludes null.
 - 'StreamSubscription' is from 'dart:async'.
  await logListener?.cancel();
        ^
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:args
 - package:build_runner_core
 - package:io
 - package:logging
 - package:build_runner
 - package:build
 - package:path
 - package:stack_trace
 - package:glob
 - package:pool
 - package:crypto
 - package:async
 - package:meta
 - package:watcher
 - package:build_config
 - package:build_resolvers
 - package:json_annotation
 - package:timing
 - package:graphs
 - package:package_config
 - package:yaml
 - package:charcode
 - package:string_scanner
 - package:code_builder
 - package:dart_style
 - package:build_daemon
 - package:pedantic
 - package:http_multi_server
 - package:shelf
 - package:pub_semver
 - package:pubspec_parse
 - package:analyzer
 - package:convert
 - package:collection
 - package:built_value
 - package:built_collection
 - package:stream_transform
 - package:http_parser
 - package:stream_channel
 - package:mime
 - package:shelf_web_socket
 - package:web_socket_channel
 - package:checked_yaml
 - package:package_resolver
 - package:source_span
 - package:matcher
 - package:quiver
 - package:front_end
 - package:typed_data
 - package:fixnum
 - package:http
 - package:term_glyph
 - package:kernel

For solutions, see https://dart.dev/go/unsound-null-safety
pub finished with exit code 1
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command flutter pub run build_runner watch --delete-conflicting-outputs --no-sound-null-safety" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

I have not opted in for null saftey, I'm aware of it but not ready to start migrating to it. Earlier I moved to flutter beta branch so I could test a project in flutter web, I did not expect this to enable null safety.

I've tried running with the suggested flag in the documentation but I still get the same error:

flutter pub run build_runner watch --delete-conflicting-outputs --no-sound-null-safety

Flutter doctor output:

[√] Flutter (Channel beta, 1.25.0-8.2.pre, on Microsoft Windows [Version
    10.0.19042.685], locale en-GB)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)     
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more
      details.
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] VS Code, 64-bit edition (version 1.52.1)
[√] Connected device (3 available)

! Doctor found issues in 1 category.
@vsmenon
Copy link
Member

vsmenon commented Jan 12, 2021

Can you share your pubspec constraints as well?

fyi - @jakemac53 - do we expect build_runner itself to be running null-safe?

@jakemac53
Copy link
Contributor

jakemac53 commented Jan 12, 2021

You need to update build_runner to version 1.10.4 or higher. That version explicitly opts out the generated script, which otherwise is a part of the user package and will pick up whatever the default language version is for the package.

@vsmenon
Copy link
Member

vsmenon commented Jan 12, 2021

Thanks - do we document that anywhere?

@jakemac53
Copy link
Contributor

The changelog for that version documents it... I don't know what we would really document or where? It is a bit of an unfortunate situation to be sure but the build/test packages are heavily broken in many ways by null safety (anything interacting with compilers is).

So you definitely need to be on the latest of each in order to work with null safety, or even upgrade to the 2.12 sdk generally.

@vsmenon
Copy link
Member

vsmenon commented Jan 12, 2021

@kwalrath @mit-mit @kevmoo - do we have a troubleshooting doc / faq for adding items like this?

@mit-mit
Copy link
Member

mit-mit commented Jan 12, 2021

Maybe we can cover this on https://dart.dev/null-safety/faq ?

@kwalrath
Copy link
Contributor

Maybe we can cover this on https://dart.dev/null-safety/faq ?

That's essentially a copy of the internal FAQ. Not sure whether we might want to update that too, or whether this is external only (and if so, how we should handle that).

/cc @davidmorgan @ryanmcginnis

@davidmorgan
Copy link
Contributor

This is external only, so advice can be added to the external faq, no change needed to the internal one. Thanks :)

(Part of the reason we copied rather than trying to keep the two exactly in line is we knew there would be cases that didn't fit in both).

@jimmyff
Copy link
Author

jimmyff commented Jan 13, 2021

I downgrading flutter back to stable yesterday which seemed to fix the issue however this morning I started getting null safety errors again but this time in a flutter project that imports the op package. Errors were saying that named parameters needed a default etc. I updated the build_runner to 1.10.4 in the op package as suggested by @jakemac53 and this resolved the new errors in the flutter project.

Just wanted to point out that having dependencies on a package that doesn't have the necessary version of build_runner could result in some difficult to debug null-saftey errors without opt-in situations.

@jakemac53
Copy link
Contributor

Just wanted to point out that having dependencies on a package that doesn't have the necessary version of build_runner could result in some difficult to debug null-saftey errors without opt-in situations.

Packages should only have a dev_dependency on build_runner which won't affect your version solve - if they have a regular dependency on it I would file an issue asking them to move that to a dev dependency. The exception being if the package is some sort of tool that wraps build_runner.

@devoncarew devoncarew added the area-build Use area-build for SDK build issues. label Jan 13, 2021
@AlexVegner
Copy link

AlexVegner commented Feb 15, 2021

Workaround for: 1.26.0-17.5.pre

dev_dependencies:
  build_runner: '1.11.1'

dependency_overrides:
  analyzer: '0.40.6'

@MatrixDev
Copy link

Is this issue still being looked at? I also receive the same errors using Dart 1.12 and Flutter 2.0.2.

Only difference is that list of libraries is smaller:

flutter pub run build_runner build --delete-conflicting-outputs --no-sound-null-safety
Failed to precompile build_runner:build_runner:
/users/matrixdev/Library/Flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-1.12.2/bin/build_runner.dart:91:49: Warning: Operand of null-aware operation '??' has type 'bool' which excludes null.
    var verbose = parsedArgs.command['verbose'] as bool ?? false;
                                                ^
/users/matrixdev/Library/Flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-1.12.2/bin/build_runner.dart:101:9: Warning: Operand of null-aware operation '?.' has type 'StreamSubscription<dynamic>' which excludes null.
 - 'StreamSubscription' is from 'dart:async'.
  await logListener?.cancel();
        ^
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:args
 - package:build_runner_core
 - package:io
 - package:build_runner
 - package:build_config
 - package:build_daemon
 - package:code_builder
 - package:http_multi_server
 - package:shelf_web_socket
 - package:web_socket_channel

For solutions, see https://dart.dev/go/unsound-null-safety
pub finished with exit code 1

@jakemac53
Copy link
Contributor

@MatrixDev you are seeing a slightly different issue - it appears that the main wrapper build_runner script is running with sound null safety enabled when it shouldn't. That looks like a duplicate of dart-lang/build#3046 to me, I would follow along there. We still haven't been able to gather enough information to understand what is going wrong though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-build Use area-build for SDK build issues.
Projects
None yet
Development

No branches or pull requests

9 participants