Skip to content

DartUri: Cannot read packages spec in workspace environment #161469

Closed

Description

@JHubi1

Steps to reproduce

Short: Create a flutter project inside a workspace and add a web target.

  1. Create an empty folder
  2. Add a pubspec.yaml with a name and workspace attribute
  3. Create a subfolder using flutter create --platforms=web -e app
  4. Add resolution: workspace to its pubspec.yaml and the package directory to the root pubspec
  5. Run the project in web

Expected results

Not to print anything (-> not to throw errors)

Actual results

DartUri: Cannot read packages spec: file:///C:/Users/jakob/Documents/GitHub/upsheep/packages/test_app/.dart_tool/package_config.jsonError: PathNotFoundException: Cannot open file, path = 'C:\Users\jakob\Documents\GitHub\upsheep\packages\test_app\.dart_tool\package_config.json' (OS Error: Das System kann die angegebene Datei nicht finden., errno = 2)

(second part is German and means something along the lines of "The system could not find the specified file")

I did some digging and by judging by previous issues, I believe this is an issue directly related to Flutter.
It occurs because pub get deletes said .dart_tool/package_config.json file and "relocates" it to the root project.

Running the project still works, but on every refresh the error is printed. Not very cool

Code sample

Code sample

Not applicable, see "Steps to reproduce"

Screenshots or Video

Screenshots / Video demonstration

Not applicable

Logs

The instructions say I have to add --verbose, it's quite a long output, so I also attached the output without verbose.

Logs without Verbose
C:\Users\jakob\Documents\GitHub\upsheep\packages\test_app>flutter run
Resolving dependencies in `C:\Users\jakob\Documents\GitHub\upsheep`...
Downloading packages...
  _fe_analyzer_shared 76.0.0 (78.0.0 available)
  analyzer 6.11.0 (7.1.0 available)
  async 2.11.0 (2.12.0 available)
  boolean_selector 2.1.1 (2.1.2 available)
  characters 1.3.0 (1.4.0 available)
  clock 1.1.1 (1.1.2 available)
  collection 1.19.0 (1.19.1 available)
  fake_async 1.3.1 (1.3.2 available)
  leak_tracker 10.0.7 (10.0.8 available)
  leak_tracker_flutter_testing 3.0.8 (3.0.9 available)
  matcher 0.12.16+1 (0.12.17 available)
  material_color_utilities 0.11.1 (0.12.0 available)
  meta 1.15.0 (1.16.0 available)
  path 1.9.0 (1.9.1 available)
  source_span 1.10.0 (1.10.1 available)
  stack_trace 1.12.0 (1.12.1 available)
  stream_channel 2.1.2 (2.1.4 available)
  string_scanner 1.3.0 (1.4.1 available)
  term_glyph 1.2.1 (1.2.2 available)
  test 1.25.8 (1.25.14 available)
  test_api 0.7.3 (0.7.4 available)
  test_core 0.6.5 (0.6.8 available)
  vm_service 14.3.0 (15.0.0 available)
Got dependencies in `C:\Users\jakob\Documents\GitHub\upsheep`!
23 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.
Launching lib\main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...             23,3s
DartUri: Cannot read packages spec: file:///C:/Users/jakob/Documents/GitHub/upsheep/packages/test_app/.dart_tool/package_config.jsonError:
PathNotFoundException: Cannot open file, path = 'C:\Users\jakob\Documents\GitHub\upsheep\packages\test_app\.dart_tool\package_config.json' (OS
Error: Das System kann die angegebene Datei nicht finden.
, errno = 2)
This app is linked to the debug service: ws://127.0.0.1:51345/YC9YGKFnjaI=/ws
Debug service listening on ws://127.0.0.1:51345/YC9YGKFnjaI=/ws

🔥  To hot restart changes while running, press "r" or "R".
For a more detailed help message, press "h". To quit, press "q".

A Dart VM Service on Chrome is available at: http://127.0.0.1:51345/YC9YGKFnjaI=
The Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9102?uri=http://127.0.0.1:51345/YC9YGKFnjaI=

Application finished.

C:\Users\jakob\Documents\GitHub\upsheep\packages\test_app>
Logs with Verbose

This reveals a lot more DartUri errors than initially thought. Wow

Too long, see https://pastebin.com/PGQN912h

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.27.1, on Microsoft Windows [Version 10.0.26100.2605], locale de-DE)
    • Flutter version 3.27.1 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 17025dd882 (4 weeks ago), 2024-12-17 03:23:09 +0900
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at C:\Users\jakob\AppData\Local\Android\Sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)
    • 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 2022 17.10.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.10.35027.167
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.1)
    • Android Studio at C:\Program Files\Android\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 = C:\Program Files\Android\Android Studio
    • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)

[√] VS Code, 64-bit edition (version 1.96.2)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.102.0

[√] Connected device (2 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26100.2605]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 131.0.6778.265

[√] Network resources
    • All expected network resources are available.

• No issues found!

Activity

  1. ERGataullin commented on Jan 11, 2025

    @ERGataullin

    Got the same problem yesterday
    This way the app in workspace becomes not debuggable, because flutter can't understand paths to packages, causing not working breakpoints
    Makes workspaces feature unusable

  2. added
    in triagePresently being triaged by the triage team
    on Jan 13, 2025
  3. huycozy commented on Jan 13, 2025

    @huycozy
    Member

    Hi @JHubi1

    Create a flutter project inside a workspace

    Can you please be more specific on "workspace" here? Is it just a simple folder or Is there any specific setup/configuration?

  4. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 13, 2025
  5. ERGataullin commented on Jan 13, 2025

    @ERGataullin
  6. JHubi1 commented on Jan 13, 2025

    @JHubi1
    Author

    Yes, Dart Workspaces. I believe this issue should have quite a high priority. Flutter not working with a native Dart feature is something that should not be a thing

  7. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 13, 2025
  8. davidmigloz commented on Jan 13, 2025

    @davidmigloz
    Contributor

    After migrating to workspaces (Flutter 3.27.1 / Dart 3.6.0), I also started facing this issue on web in combination with random TypeErrors: (update: the TypeErrors were caused by a dependency)

    Stacktrace
    Waiting for connection from debug service on Chrome...
    DartUri: Cannot read packages spec: file:///Users/xxx/.dart_tool/package_config.jsonError: PathNotFoundException: Cannot open file, path = '/Users/xxx/.dart_tool/package_config.json' (OS Error: No such file or directory, errno = 2)
    This app is linked to the debug service: ws://127.0.0.1:51771/kcMw-lhaGr8=/ws
    Debug service listening on ws://127.0.0.1:51771/kcMw-lhaGr8=/ws
    TypeError: Cannot read properties of undefined (reading 'xxx')
    packages/xxx/injection.dart 59:9                          get _all
    packages/xxx/injection.dart 66:31                         <fn>
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19  <fn>
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23  <fn>
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3   _asyncStartSync
    packages/xxx/injection.dart 65:23                         registerDependencies
    packages/xxx/main.dart 10:19                              <fn>
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19  <fn>
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23  <fn>
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3   _asyncStartSync
    packages/xxx/main.dart 7:14                               main$
    web_entrypoint.dart 24:31                                            <fn>
    lib/ui_web/ui_web/initialization.dart 41:15                          <fn>
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19  <fn>
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23  <fn>
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 581:31  <fn>
    dart-sdk/lib/async/zone.dart 1676:54                                 runUnary
    dart-sdk/lib/async/future_impl.dart 204:18                           handleValue
    dart-sdk/lib/async/future_impl.dart 902:44                           handleValueCallback
    dart-sdk/lib/async/future_impl.dart 931:13                           _propagateToListeners
    dart-sdk/lib/async/future_impl.dart 707:5                            [_completeWithValue]
    dart-sdk/lib/async/future_impl.dart 777:7                            callback
    dart-sdk/lib/async/schedule_microtask.dart 40:11                     _microtaskLoop
    dart-sdk/lib/async/schedule_microtask.dart 49:5                      _startMicrotaskLoop
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 186:7   <fn>
    

    It only happens in debug mode, release builds work fine.

    Similar issue: #161504

  9. huycozy commented on Jan 14, 2025

    @huycozy
    Member

    @JHubi1 Can you please provide a a completed and minimal reproducible code sample in a GitHUb repository? And please add a license in the repository under some open-source license (e.g. MIT, Apache, BSD, GPL) so that we may look into it. Thanks!

  10. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 14, 2025
  11. JHubi1 commented on Jan 14, 2025

    @JHubi1
    Author

    @huycozy created it here: https://github.com/JHubi1/flutter_issue_example_161469
    Hope it works (or better not)

  12. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 14, 2025
  13. huycozy commented on Jan 15, 2025

    @huycozy
    Member

    Thank you so much for the repo. Reproduced the issue on Flutter Channel master, ``3.28.0-2.0.pre.38724`. Although the app can run, there is error message from the output console:

    Output log
    Launching lib/main.dart on Chrome in debug mode...
    DartUri: Cannot read packages spec: file:///Users/huynq/Documents/NEVERCODE.IO/RepoduceProjects/OPClone/flutter_issue_example_161469/packages/test_app/.dart_tool/package_config.jsonError: PathNotFoundException: Cannot open file, path = '/Users/huynq/Documents/NEVERCODE.IO/RepoduceProjects/OPClone/flutter_issue_example_161469/packages/test_app/.dart_tool/package_config.json' (OS Error: No such file or directory, errno = 2)
    This app is linked to the debug service: ws://127.0.0.1:60975/v9zjpGZISic=/ws
    Debug service listening on ws://127.0.0.1:60975/v9zjpGZISic=/ws
    Connecting to VM Service at ws://127.0.0.1:60975/v9zjpGZISic=/ws
    Connected to the VM Service.
  14. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    and removed
    in triagePresently being triaged by the triage team
    on Jan 15, 2025
  15. 3 remaining items

  16. ERGataullin commented on Jan 24, 2025

    @ERGataullin

    Reproducible in 3.27.3

  17. bkonyi commented on Jan 28, 2025

    @bkonyi
    Contributor

    FYI @sigurdm, can you take a look?

  18. added
    P1High-priority issues at the top of the work list
    triaged-toolTriaged by Flutter Tool team
    on Jan 28, 2025
  19. sigurdm commented on Jan 30, 2025

    @sigurdm
    Contributor

    Seems like the message comes from here: https://github.com/dart-lang/webdev/blob/a7ea61ffa07e899fe7bcb385f8cbca88427e0c0a/dwds/lib/src/utilities/dart_uri.dart#L216

    If I'm not wrong the LoadStrategy is provided by flutter tools here:

    which calls https://github.com/dart-lang/webdev/blob/a7ea61ffa07e899fe7bcb385f8cbca88427e0c0a/dwds/lib/src/loaders/frontend_server_strategy_provider.dart#L141 which passes null as packageConfigUri - I think that it should instead get the packageConfigUri from BuildInfo somehow - probably requires an update to package:dwds.

    @srujzs and @jyameo might have more context.

  20. srujzs commented on Jan 30, 2025

    @srujzs
    Contributor

    It should be calling https://github.com/dart-lang/webdev/blob/a7ea61ffa07e899fe7bcb385f8cbca88427e0c0a/dwds/lib/src/loaders/frontend_server_strategy_provider.dart#L171 by default, but the effect is the same in that we don't store a packageConfigPath. Let me see if trying out what @sigurdm suggested works.

  21. srujzs commented on Jan 31, 2025

    @srujzs
    Contributor

    FYI - it looks like it avoids the issues (the aforementioned logs do not appear). There is a similar issue on the webdev side: dart-lang/webdev#2575. DWDS should be updated to accept and use the path for every strategy, and Flutter tools should be updated to pass it. I'll work with @jyameo here to land a change.

  22. sigurdm commented on Jan 31, 2025

    @sigurdm
    Contributor

    I'll work with @jyameo here to land a change.

    Thanks!

  23. jyameo commented on Feb 11, 2025

    @jyameo
    Contributor

    I have published a new version of DWDS v24.3.5 with the fix for this issue. I believe it should be pickup on the next flutter release.

  24. github-actions commented on Feb 26, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  25. locked as resolved and limited conversation to collaborators on Feb 26, 2025
  26. self-assigned this
    on Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listfound in release: 3.27Found to occur in 3.27found in release: 3.28Found to occur in 3.28has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions