Pub: No .dart_tool/package_config.json file found when running build_runner

Created on 31 Oct 2019  Â·  19Comments  Â·  Source: dart-lang/pub

Context:

  • DevTools integration tests are failing on Flutter channel master when trying to run $ flutter pub run build_runner build -o web:build --delete-conflicting-outputs --no-release with error message:
pub run build_runner serve • 5550 • STDERR • No .dart_tool/package_config.json file found, please run "pub get" first.
  • Tried switching to Flutter dev channel and it works fine

Link to TravisCI Job / full log:

https://travis-ci.org/flutter/devtools/jobs/605245486?utm_medium=notification&utm_source=github_status

Requested issue informations:

  • Dart SDK Version (dart --version)

2.6.0-dev.8.2.flutter-d50c158d42

  • What package(s) from this repo you are using, and the version (i.e. build_runner 0.7.12)

    • _If you are not sure, try checking your pubspec.lock file._

build_runner-1.7.2**

  • What builder(s) you are using (or writing yourself). Try to give a short summary of what they do.

none

  • Whether you are using Windows, MacOSX, or Linux (if applicable)

Tests fail both on MacOS & Linux

  • Whether you are using Chrome, Safari, Firefox, Edge (if applicable)

not applicable

  • Any other packages or constraints we should know about

Most helpful comment

Are we supposed to manually run pub get instead of flutter pub get?
We do run flutter pub get though before running the build_runner (which is triggered by running flutter test)

All 19 comments

tagging in:
@grouma
@jacob314
@jonahwilliams

@jakemac53

This is not supposed to be a required file.

cc @jonasfj @sigurdm I am transferring this issue to the pub repo

Fwiw the bug here looks to be that the newer pub requires a .dart_tool/package_config.json but you may not have ran a pub get yet after upgrading your sdk.

pub run checks that:

  • pubspec.lock satisfies pubspec.yaml, and
  • .packages is up-to-date with pubspec.lock and (as of recently),
  • that .dart_tool/package_config.json exists and is up-to-date with pubspec.lock (and path dependencies).

Doing pub get should resolve this issue, @albertusangga is that not the case?

Does any one have a suggestion for a better error message that would convince the user to run pub get again. I'm sure more users will raise this question, so any clarification we can do in the message will likely help many users.

Maybe the .dart_tool/package_config.json part is confusing people? We could hide the details of that behind the --verbose flag and instead make an assumption that they just updated their sdk and need to re-run pub get. In that case the error message would be something like:

Your sdk has been updated since the last run - please re-run "pub get"

I think pub may already record the previous sdk version as well so we could check for this scenario more directly?

Are we supposed to manually run pub get instead of flutter pub get?
We do run flutter pub get though before running the build_runner (which is triggered by running flutter test)

If you have the dart and flutter sdks things definitely might get more complicated here... but in general I think you would need to use the sdk that you want to run pub run with.

So if you use flutter pub run then you need to do flutter pub get and those things should be compatible. It is possible this doesn't actually work as you would expect today.

Yes that is what we do, running flutter pub get before triggering flutter pub run build_runner build -o web:build --delete-conflicting-outputs --no-release, and it seems to be not working.
Any idea on how to fix this?

That is very weird, maybe @jonasfj would have some ideas. As long as the pub version is consistent it should work.

You could try manually deleting your pubspec.lock file just in case... maybe it thinks everything is up to date and isn't recreating those files.

Ok I think I know the root cause for our error now.
This is caused by our integration test running flutter clean first (which ended up deleting the .dart_tool folder before executing the flutter pub run build_runner ...), but this works fine before the Flutter's dart SDK version updates to 2.6.0-dev.8.2.flutter-d50c158d42.

If I'm correct, I think there is a change in the latest dart SDK that prevented running pub get automatically? Because I tried this with earlier dart sdk, running flutter clean and then trying to run pub run directly without pub get seems to work fine.

Is this correct?

Ahhh this makes sense. The difference is that previously deleting the .dart_tool directory at any point was perfectly fine to do (pub only put precompiled binaries in there). Now that means you have to re-run pub get.

There are a few potential resolutions here:

  • Make flutter clean delete only specific sub-directories of .dart_tool

    • I don't really like this option because it means there might be scenarios it doesn't help you recover from.

  • flutter clean could delete the .packages file

    • I believe this would give you a better error message from pub

  • flutter clean could re-run flutter pub get

    • This might be unexpected and cause other problems

  • Detect this scenario and output a nicer message from pub similar to what I suggested above.

    • Users aren't supposed to care about the .dart_tool/ dir or anything under it so removing that from the message would be less confusing.

In general I think we should focus on the error messages from pub and improving that. I think it is totally fine and intuitive that you have to do a new flutter pub get after doing a flutter clean. The main question then is how to present that to the user.

In general I think we should focus on the error messages from pub and improving that. I think it is totally fine and intuitive that you have to do a new flutter pub get after doing a flutter clean. The main question then is how to present that to the user.

I agree.

The contract for flutter clean is just that it deletes those directories, not that it is safe to build again without running pub get first.

We hit this in an uncommon case where we're using the flutter tool to call pub run after the clean. Our real confusion here is that it did work, and then it stopped working.

So long as the error is just that pub get needs to be re-run, and the error message communicates that, I am OK with closing this issue as intended behavior.

I'll close this as intended behavior.

What is the workaround? When I run pub run build_runner build instead of flutter pub run build_runner build I get: The Flutter SDK is not available. But if I run it with flutter at the start I get: The pubspec.yaml file has changed since the pubspec.lock file was generated, please run "pub get" again. pub finished with exit code 65.

I have been stuck on this for hours.

Are you using generate: true and flutter_gen, see https://github.com/flutter/flutter/issues/73870

@jonasfj I'm not using generate: anywhere. I am using flutter_gen though:

flutter_gen:
  output: lib/

version (just updated to see if it fixed it): flutter_gen: ^2.0.1

adding --verbose to flutter pub run build_runner build:

[ +114 ms] executing: [/Users/benjaminfarquhar/development/flutter/] git -c log.showSignature=false log -n 1
--pretty=format:%H
[  +71 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] c5a4b4029c0798f37c4a39b479d7cb75daa7b05c
[        ] executing: [/Users/benjaminfarquhar/development/flutter/] git tag --points-at
c5a4b4029c0798f37c4a39b479d7cb75daa7b05c
[  +27 ms] Exit code 0 from: git tag --points-at c5a4b4029c0798f37c4a39b479d7cb75daa7b05c
[        ] 2.0.1
[  +59 ms] executing: [/Users/benjaminfarquhar/development/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +15 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [/Users/benjaminfarquhar/development/flutter/] git ls-remote --get-url origin
[  +15 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +71 ms] executing: [/Users/benjaminfarquhar/development/flutter/] git rev-parse --abbrev-ref HEAD
[  +30 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[   +9 ms] executing: sw_vers -productName
[  +21 ms] Exit code 0 from: sw_vers -productName
[        ] macOS
[        ] executing: sw_vers -productVersion
[  +20 ms] Exit code 0 from: sw_vers -productVersion
[        ] 11.2.2
[        ] executing: sw_vers -buildVersion
[  +24 ms] Exit code 0 from: sw_vers -buildVersion
[        ] 20D80
[   +9 ms] executing: sysctl hw.optional.arm64
[  +12 ms] Exit code 1 from: sysctl hw.optional.arm64
[        ] sysctl: unknown oid 'hw.optional.arm64'
[  +98 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +4 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +58 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[  +49 ms] Using /Users/benjaminfarquhar/development/flutter/.pub-cache for the pub cache.
[        ] executing: /Users/benjaminfarquhar/development/flutter/bin/cache/dart-sdk/bin/pub run build_runner --verbose
The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated, please run "pub get" again.
[ +621 ms] "flutter run" took 755ms.
[  +24 ms] pub finished with exit code 65
[  +17 ms] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      _DefaultPub.interactively (package:flutter_tools/src/dart/pub.dart:364:7)
           <asynchronous suspension>
           #2      PackagesForwardCommand.runCommand (package:flutter_tools/src/commands/packages.dart:238:5)
           <asynchronous suspension>
           #3      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1157:12)
           <asynchronous suspension>
           #4      FlutterCommand.run.<anonymous closure>
(package:flutter_tools/src/runner/flutter_command.dart:1009:27)
           <asynchronous suspension>
           #5      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #6      AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #7      CommandRunner.runCommand (package:args/command_runner.dart:197:13)
           <asynchronous suspension>
           #8      FlutterCommandRunner.runCommand.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command_runner.dart:278:9)
           <asynchronous suspension>
           #9      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #10     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #11     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:234:5)
           <asynchronous suspension>
           #12     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
           <asynchronous suspension>
           #13     run.<anonymous closure> (package:flutter_tools/runner.dart:62:12)
           <asynchronous suspension>
           #14     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #15     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #16     runInContext (package:flutter_tools/src/context_runner.dart:73:10)
           <asynchronous suspension>
           #17     main (package:flutter_tools/executable.dart:90:3)
           <asynchronous suspension>


[ +265 ms] ensureAnalyticsSent: 254ms
[   +3 ms] Running shutdown hooks
[        ] Shutdown hooks complete
[        ] exiting with code 65

@BenjaminFarquhar, try digging into flutter_tools it looks like something is modifying your pubspec.yaml.
I think this is an orthogonal flutter issue, if not related to flutter_gen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pq picture pq  Â·  24Comments

sanjidtt picture sanjidtt  Â·  36Comments

kevmoo picture kevmoo  Â·  53Comments

jayoung-lee picture jayoung-lee  Â·  38Comments

jonasfj picture jonasfj  Â·  31Comments