简体   繁体   中英

Dart2JS Pub Build Fails to Traverse Project Folders Correctly

I'm working on a long-term project for some time now. After moving some folders around, correctly refactoring different parts of the code, Webstorm's Dart analyser is showing NO errors, but running either pub serve or pub build fails.

Pub or Dart2JS doesn't seems to be traversing folders correctly.

This is the first error I get:

[Error from Dart2JS on CS_Game_Engine|web/main.dart]:
web/UIElements/NodeSettingsItems/TextVariableEditor.dart:4:1:
Can't read 'file:///Data/ownCloud/cybersecgame/CS%20Game%20Engine/web/UIElements/Data/Variables/Variable.dart' (Could not find asset CS_Game_Engine|web/UIElements/Data/Variables/Variable.dart.).
import '../../Data/Variables/Variable.dart';
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is interesting, because the file TextVariableEditor.dart , as you see in the error, is located in the web/UIElements/NodeSettingsItems/ directory.

The file I am trying to access ( Variables.dart ) is located in web/Data/Variables/Variable.dart .

The import statement moves 2 folders up with the ../../ , but Pub or Dart2JS is not going 2 folders up, its only going 1 folder up. See the error again:

Can't read 'file:///Data/ownCloud/cybersecgame/CS%20Game%20Engine/web/UIElements/Data/Variables/Variable.dart'

It's looking for the file in the wrong place. I'm not sure what to do to fix this, and I've looked around and can't really find anything. Again, Webstorm's Dart Analyzer shows no issues, but the pub build or pub serve both fail, unable to find the file.

I've used the ../../ many times before in my code, but this is the first time it is causing issues. There are other errors similar to this, but having the same issue of not reading the ../../ correctly.

Update 1:

I've done more testing, and adding an additional ../ to the path's beginning fixes the error during the pub build . However, now Webstorm and it's Dart Analyzer is showing lots of errors since the path is obviously wrong (1 too many ../ ). This is a workaround, but not a fix. Does anybody know why pub or the Dart2JS is reading the path incorrectly? Somehow skipping one of the ../ ?

Code within the web directory should only access files in two places:

  1. Things in the web directory, via relative paths

  2. Things in packages via package: imports

#2 is interesting. This can include files within your own project, you just need to put those files in the lib directory and access them via a package:my_proj URI.

See https://github.com/dart-lang/sample-pop_pop_win/ as an example

See also https://www.dartlang.org/tools/pub/package-layout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM