Skip to content

dartanalyzer can't resolve package: URIs unless it's in the dir of the project #24116

Closed
@sethladd

Description

@sethladd

Consider this case:

  • create a dummy project (via stagehand package-simple)
  • pub get
  • cd to your home directory
  • run dartanalyzer path/to/dummy/project/bin/main.dart

Expected: analysis to work

Actual:

~ $ dartanalyzer ~/tmp/testpkg/bin/main.dart 
Analyzing [/Users/sethladd/tmp/testpkg/bin/main.dart]...
[error] Target of URI does not exist: 'package:testpkg/testpkg.dart' (/Users/sethladd/tmp/testpkg/bin/main.dart, line 4, col 8)
[warning] Undefined name 'testpkg' (/Users/sethladd/tmp/testpkg/bin/main.dart, line 4, col 42)
[warning] Undefined name 'testpkg' (/Users/sethladd/tmp/testpkg/bin/main.dart, line 8, col 25)
1 error and 2 warnings found.

If I cd into my dummy project, I can analyze:

~ $ cd tmp/testpkg/
~/tmp/testpkg $ dartanalyzer bin/main.dart 
Analyzing [bin/main.dart]...
No issues found

FWIW the VM runs the code from an arbitrary directory

~ $ dart ~/tmp/testpkg/bin/main.dart 
Hello world: 42!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions