Repository navigation
"Unable to find the library" for global evaluation when the current file is inside the lib folder #4932
Description
Describe the bug
Any attempt to execute an expression in VS Code's debug console for a Flutter app running in debug mode prints back:
1 + 1
Unable to find the library for file:///e%3A/Development/_code/Flutter/app_5/lib/main.dart
#0 DartDebugAdapter.evaluateRequest (package:dds/src/dap/adapters/dart.dart:1060:7)
<asynchronous suspension>
#1 BaseDebugAdapter.handle (package:dds/src/dap/base_debug_adapter.dart:141:7)
<asynchronous suspension>
To Reproduce
Steps to reproduce the behavior:
- Create a new app via "Flutter: New Project".
- Build it for Windows, in my case.
- Attempt to evaluate any expression in VSC's debug console.
- Observe the
unable to find the libraryaforementioned error from above.
Expected behavior
Prior to the most recent upgrade to Flutter 3+ and Dart SDK 3.2.3, it was perfectly possible not only to evaluate arbitrary operations in global context, but also to reference the declarations in the main.dart directly. This was extremely useful for custom debugging, which would allow for inspection of surgical precision within any runtime object that required additional monitoring, as needed.
It would be most useful to get such an option back. Running the DevTools (2.28.4) directly in the browser, furthermore, still allows to do just that - at any point in time, with or without the breakpoint. DevTools aren't nearly as versatile and free of friction as the standard built-in debug console within VSC, however. Having to go back and forth in and out of the IDE adds quite a bit of additional mental overhead as well, which doesn't exactly feel as absolutely necessary.
I see that the #4636 issue was closed as completed. Can this be considered a regression? The #4899 appears to have similar working, though the context seems to be limited to Dart only, with no mentioning of Flutter. The exact error appears to be different too, here.
Screenshots
Diagnostics
Workspace Environment
Dart Code extension: 3.80.0
Flutter extension: 3.80.0 (activated)
App: Visual Studio Code
App Host: desktop
Version: win 1.85.1
Workspace type: Flutter (LSP)
Dart (3.2.3): E:\Development\Flutter\3.3.10\bin\cache\dart-sdk
Flutter (3.16.6): E:\Development\Flutter\3.3.10 (Windows (windows-x64/windows))
Output from `dart info`
E:\Development\Flutter\3.3.10\bin\cache\dart-sdk\bin\dart.exe info
If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.
General info
- Dart 3.2.3 (stable) (Tue Dec 5 17:58:33 2023 +0000) on "windows_x64"
- on windows / "Windows 10 Pro" 10.0 (Build 19045)
- locale is en-US
Project info
- sdk constraint: '>=3.2.3 <4.0.0'
- dependencies: flutter
- dev_dependencies: flutter_lints, flutter_test
- elided dependencies: 2
Process info
| Memory | CPU | Elapsed time | Command line |
|---|---|---|---|
| 82 MB | -- | dart.exe | |
| 14 MB | -- | dart.exe | |
| 39 MB | -- | dart.exe | |
| 456 MB | -- | dart.exe | |
| 47 MB | -- | dart.exe | |
| 41 MB | -- | dart.exe | |
| 86 MB | -- | dart.exe | |
| 126 MB | -- | dart.exe | |
| 374 MB | -- | dart.exe | |
| 85 MB | -- | dart.exe |
Output from `flutter doctor`
E:\Development\Flutter\3.3.10\bin\flutter.bat doctor -v
[√] Flutter (Channel stable, 3.16.6, on Microsoft Windows [Version 10.0.19045.3930], locale en-US)
• Flutter version 3.16.6 on channel stable at E:\Development\Flutter\3.3.10
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 46787ee49c (2 days ago), 2024-01-09 14:36:07 -0800
• Engine revision 3f3e560236
• Dart version 3.2.3
• DevTools version 2.28.4
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at E:\Programs\AndroidSDK
• Platform android-33, build-tools 30.0.3
• Java binary at: E:\Programs\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Community 2019 16.11.21)
• Visual Studio at E:\Development\VS\Community
• Visual Studio Community 2019 version 16.11.33027.164
• Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 4.2)
• Android Studio at E:\Programs\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = E:\Programs\Android Studio
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.3930]
• Chrome (web) • chrome • web-javascript • Google Chrome 120.0.6099.217
• Edge (web) • edge • web-javascript • Microsoft Edge 120.0.2210.121
[√] Network resources
• All expected network resources are available.
• No issues found!


Activity
[-]"Unable to find the library" in global evaluation context, no breakpoint[/-][+]"Unable to find the library" for global evaluation context on Windows[/+][-]"Unable to find the library" for global evaluation context on Windows[/-][+]"Unable to find the library" for global evaluation context on Windows for Flutter apps[/+]DanTup commentedon Jan 15, 2024
I can repro.. seems to be specific to Windows and Flutter. On macOS, Dart+Flutter work and on Windows, Dart works.
For Windows + Flutter I get:
It seems unrelated to the casing of the drive letter (a common cause of errors like this) or the encoded colon (sending
C:/does not fix anything).DanTup commentedon Jan 15, 2024
Here's the code where we try to locate the library:
https://github.com/dart-lang/sdk/blob/ff1c32a52f1f1fd218b4e67db82697382ccddd13/pkg/dds/lib/src/dap/isolate_manager.dart#L1357
We get all scripts from the VM and try to find the ones that match some version of the incoming URI. The computed candidate URIs in this case are:
file:///c%3A/Dev/Test%20Projects/dartcode_4932/lib/main.dartfile:///C:/Dev/Test%20Projects/dartcode_4932/lib/main.dartfile:///c:/Dev/Test%20Projects/dartcode_4932/lib/main.dartHowever the only
main.dartin the result of runninggetScripts()is:This has a
package:URI and not a file URI, so we don't match.Two thoughts:
resolvePathToUridid not correctly turn thefile:///URI into apackage:URIgetScripts()call returns different things compared to macOSEdit:
The difference between Dart and Flutter was actually not a difference between Dart and Flutter, it was because in Dart I was testing in the bin folder (which doesn't have a package URI).
In that case, we do see a script with a file: URI:
But trying a
libfile in Dart also fails:Edit2: Turns out, it fails on macOS for Dart lib folder too:
Similar to Windows, we have this candidate URI:
file:///Users/danny/Desktop/dart_samples/dartcode_4932_dart/lib/dartcode_4932_dart.dartBut in scripts, we only have the
package:URI:ScriptRef id: libraries/@19169571/scripts/package%3Adartcode_4932_dart%2Fdartcode_4932_dart.dart/18d0d253e77, uri: package:dartcode_4932_dart/dartcode_4932_dart.dart]Which raises the question... Why does it work for Flutter on MacOS? 🤔
Turns out it does not. It's not clear what I tested previously, but now on latest master I'm seeing the same issue:
[-]"Unable to find the library" for global evaluation context on Windows for Flutter apps[/-][+]"Unable to find the library" for global evaluation when the current file is inside the lib folder[/+]DanTup commentedon Jan 15, 2024
Working on a fix at https://dart-review.googlesource.com/c/sdk/+/346400. Unfortunately it's not possible to work around the issue in the VS Code extension so the fix is going to come via a future SDK release.
[dds][dap] Fix global evaluation inside package: files
DanTup commentedon Jan 24, 2024
Fixed by dart-lang/sdk@a95b584. Ships in a future SDK release (rather than a Dart-Code release).
dotkaio commentedon May 25, 2024
the error persists
DanTup commentedon May 28, 2024
@dotkaio if you're on the latest version of the Dart/Flutter SDK and also the latest version of VS Code + Dart extension, could you file a new issue about this and include a log file from reproducing this in a sample project?
Thanks!
iulian0512 commentedon Aug 19, 2024
@DanTup is global evaluation supposed to work when attached to an android device(flutter app) ?
DanTup commentedon Aug 19, 2024
@iulian0512 if you have a Dart file open, yep. If it doesn't work for you, please file a new issue with steps to reproduce and a screenshot of what you see. Thanks!