Sdk: "warning - The include file cannot be found" when using pedantic with a nested module

Created on 16 Apr 2020  Â·  9Comments  Â·  Source: dart-lang/sdk

Not sure if the root cause is pedantic but I figured I would start here.

Issue
The following warning is returned by flutter analyze despite correctly adding pedantic as a dependency.
warning • The include file package:pedantic/analysis_options.yaml in /Users/jrai/git/pedantic_bug/analysis_options.yaml cannot be found • analysis_options.yaml:1:11 • include_file_not_found

Flutter Version
This is reproducible on Flutter Beta 1.17.0 but not on Flutter Stable v1.12.13+hotfix.9.

Reproduction Steps

  1. Create a Flutter project.
  2. Create a Dart package within the project from step 1's directory.
  3. Add the Dart package as a dependency of the Flutter project.
  4. Use the Dart package in the Flutter project.
  5. Add pedantic in the Flutter project and create the analysis_options.yaml file.
  6. flutter pub get in both projects
  7. flutter analyze

Sample repo here: https://github.com/MisterJimson/pedantic-bug
This single commit introduces the issue: https://github.com/MisterJimson/pedantic-bug/commit/5ad95596cf4730398f42a07fba42013baff08de3

Notes
Step 4 is required, you need to use some code from the package
Able to reproduce with either pedantic 1.8.0+1 or 1.9.0
If you add pedantic to the Dart package, the issue goes away.

jrai@Jasons-MacBook-Pro pedantic_bug % flutter doctor -v
[✓] Flutter (Channel beta, v1.17.0, on Mac OS X 10.15.4 19E287, locale en-CA)
    • Flutter version 1.17.0 at /Users/jrai/dev/flutter
    • Framework revision d3ed9ec945 (10 days ago), 2020-04-06 14:07:34 -0700
    • Engine revision c9506cb8e9
    • Dart version 2.8.0 (build 2.8.0-dev.18.0 eea9717938)


[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/jrai/Library/Android/sdk
    • Platform android-29, build-tools 28.0.3
    • ANDROID_HOME = /Users/jrai/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.4, Build version 11E146
    • CocoaPods version 1.9.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[!] Android Studio (version 3.5)
    • Android Studio at /Users/jrai/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/191.5977832/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[!] IntelliJ IDEA Ultimate Edition (version 2020.1)
    • IntelliJ at /Users/jrai/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

[✓] VS Code (version 1.43.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.9.1

[✓] Connected device (3 available)
    • iPhone 11 Pro • 592B3AFC-563B-4C91-AE69-E57A7F3E0C5C • ios            • com.apple.CoreSimulator.SimRuntime.iOS-13-4 (simulator)
    • Chrome        • chrome                               • web-javascript • Google Chrome 81.0.4044.113
    • Web Server    • web-server                           • web-javascript • Flutter Tools


area-analyzer

Most helpful comment

As maintainer of the lint package, I receive this error report almost every week. It's by far the most reported issue.

I'm also facing this issue in all of my multi-module Flutter projects. I'm currently using Dart version 2.9.0 (build 2.9.0-21.2.beta), Flutter version 1.20.0-7.2.pre

flutterProject/
- analysis_options.yaml
- pubspec.yaml
- pkg/
  someFlutterPackage/
  - analysis_options.yaml
  - pubspec.yaml
  someDartPackage/
  - analysis_options.yaml
  - pubspec.yaml
  ...

All packages contain a pubspec.yaml with lint: ^1.1.1 in dev_dependencies and include: package:lint/analysis_options.yaml in analysis_options.yaml.

Analyzer always reports warning: The include file package:lint/analysis_options.yaml in flutterProject/analysis_options.yaml cannot be found. (include_file_not_found at analysis_options.yaml:1) for my top-level flutter project via IntelliJ (macOS).

When run via CLI on macOS the error is shown twice 👯

warning • The include file package:lint/analysis_options.yaml in flutterProject/analysis_options.yaml cannot be found • analysis_options.yaml:1:11 • include_file_not_found
warning • The include file package:lint/analysis_options.yaml in flutterProject/analysis_options.yaml cannot be found • analysis_options.yaml:1:11 • include_file_not_found

The problem can be fixed temporarily in IDEs by deleting the include line, hit save, and add the line again. The error is gone for the current analyzer session and shows up again after restarting the server.

Interestingly, the error doesn't show up on CI (Github Actions, linux). This leads me to believe that it's caused by a timing issue, some form of race condition.

The error exists for quite some time. I remember first seeing it in 2018 in IntelliJ and VSCode. It never showed up in CLI and restarting the analysis server usually resolved it. Not anymore.
Since mid 2020 it is a permanent issue. The behaviour change must be introduced after Dart 2.7. I can't recall how Dart 2.8 behaved.

It is now breaking my workflow. I can't use flutter analyze as pre-commit hook anymore because it always fails with this annoying warning.

@bwilkerson @matanlurey This issue misses the analyzer label

All 9 comments

I think the directory structure we're looking at looks like the following:

  analysis_options.yaml
  pubspec.haml
  dartPackage
    pubspec.yaml

Is that correct? And is it the case that the dependency on pedantic was added to the pubspec.yaml file in flutterProject but not the pubspec.yaml file in dartPackage?

If so, then the problem is the missing dependency in the pubspec.yaml file in dartPackage. The pubspec.yaml file determines how to resolve package: URIs, and the code in the dartPackage will "inherit" the analysis_options.yaml file from the parent directory, but will use it's local resolution of URIs to try to resolve the reference to package:pedantic and fail because there is no binding for it.

Is that correct? And is it the case that the dependency on pedantic was added to the pubspec.yaml file in flutterProject but not the pubspec.yaml file in dartPackage?

Indeed it is. The link to the sample repo in my initial report demonstrates this.

Good to know about inheriting analysis_options. I wonder why this is reproducible on beta but not on stable?

That I don't know.

Is https://github.com/dart-lang/sdk/commit/85e56848631b3d320d935dfb23bcc35c31204832 a factor here?

FWIW I've never seen this error show up when I invoke dartanalyzer, even with an invalid include:...

This is very weird. I am on dev channel and I see warning in Dart Analysis tab in my IDE. To get rid of that warning, I first comment the line

include: package:pedantic/analysis_options.yaml

Save the file using cmd + s, then uncomment the line and again save with cmd + s, the warning shown by the tab is now gone.

However, this is not a full solution, because when I run flutter analyze command, I get the same error:

The include file package:pedantic/analysis_options.yaml in /project/analysis_options.yaml cannot be found • analysis_options.yaml:1:11 •
       include_file_not_found

PS: In programming I am extremely scared of magics.

For the record, I was using a different analysis package called lint https://pub.dev/packages/lint and I got the same error:

warning • The include file package:lint/analysis_options.yaml in /home/[redacted]/analysis_options.yaml cannot be found • analysis_options.yaml:1:11 • include_file_not_found

I switched to pedantic to see if the issue went away but I got the same.

This is running from terminal. The issue also appears on IntelliJ IDEA.

Edit: As talked with other people, they see the same issue with the package "effective_dart", seems to be a general issue in the framework and not an issue with "pedantic"

As maintainer of the lint package, I receive this error report almost every week. It's by far the most reported issue.

I'm also facing this issue in all of my multi-module Flutter projects. I'm currently using Dart version 2.9.0 (build 2.9.0-21.2.beta), Flutter version 1.20.0-7.2.pre

flutterProject/
- analysis_options.yaml
- pubspec.yaml
- pkg/
  someFlutterPackage/
  - analysis_options.yaml
  - pubspec.yaml
  someDartPackage/
  - analysis_options.yaml
  - pubspec.yaml
  ...

All packages contain a pubspec.yaml with lint: ^1.1.1 in dev_dependencies and include: package:lint/analysis_options.yaml in analysis_options.yaml.

Analyzer always reports warning: The include file package:lint/analysis_options.yaml in flutterProject/analysis_options.yaml cannot be found. (include_file_not_found at analysis_options.yaml:1) for my top-level flutter project via IntelliJ (macOS).

When run via CLI on macOS the error is shown twice 👯

warning • The include file package:lint/analysis_options.yaml in flutterProject/analysis_options.yaml cannot be found • analysis_options.yaml:1:11 • include_file_not_found
warning • The include file package:lint/analysis_options.yaml in flutterProject/analysis_options.yaml cannot be found • analysis_options.yaml:1:11 • include_file_not_found

The problem can be fixed temporarily in IDEs by deleting the include line, hit save, and add the line again. The error is gone for the current analyzer session and shows up again after restarting the server.

Interestingly, the error doesn't show up on CI (Github Actions, linux). This leads me to believe that it's caused by a timing issue, some form of race condition.

The error exists for quite some time. I remember first seeing it in 2018 in IntelliJ and VSCode. It never showed up in CLI and restarting the analysis server usually resolved it. Not anymore.
Since mid 2020 it is a permanent issue. The behaviour change must be introduced after Dart 2.7. I can't recall how Dart 2.8 behaved.

It is now breaking my workflow. I can't use flutter analyze as pre-commit hook anymore because it always fails with this annoying warning.

@bwilkerson @matanlurey This issue misses the analyzer label

Its not just on macOS, I'm seeing exactly the same thing on Linux as reported by @passsy , including the warning being shown twice! Likewise in VSCode, just editing and saving the analysis_options.yaml causes the warning to go away only in VSC until you use the palette Dart: Restart Analysis Server command,

But for me that made me suspicious as I happened to have 2 sub directories with dart packages in them while another Flutter app project with no packages inside it did not show the warning.

So... I've done some experimenting and seems that it's enough simply to just have a sub-dir in your top-level Flutter package with nothing but a minimal pubspec.yaml:

name:  test
description: just a test 
version: 0.0.1

to cause running flutter analyze at the top level package to show the warning line, once for every subdir containing a pubspec.yaml 😞

The good news is that at least I've been able to make flutter analyze usable for me in CI and make the warnings go away by adding my package sub-directories to the exclude: clause in my analysis_options.yaml.

I can confirm @maks findings.
This is not a problem in Flutter app projects or libraries/packages that don't contain any sub projects (example).

What always leads to this error is creating a new plugin project and adding any of lint/pedantic/effective_dart as the plugin template generates an example folder.
Same thing happens with the package template as soon as one adds an example or other sub project.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matanlurey picture matanlurey  Â·  3Comments

DartBot picture DartBot  Â·  3Comments

xster picture xster  Â·  3Comments

emilniklas picture emilniklas  Â·  3Comments

DartBot picture DartBot  Â·  3Comments