3

I am using the WebStorm 8 IDE to build a dart web app. I have the following directory structure:

root
   web
      main.dart
   lib
   packages
      browser
      intl
         intl.dart
   pubspec.lock
   pubspec.yaml

In main.dart I have the following import statment: import "package:intl/intl.dart";

However when I try and compile main.dart to javascript I get the following error:

dart2js
Error occurred:
/Path/To/Project/root/web/main.dart:2:8:
Error: Can't read 'package:intl/intl.dart' (Error reading '/Path/To/Project/root/web/packages/intl/intl.dart' (OS Error: No such file or directory, errno = 2)).
import "package:../packages/intl/intl.dart";
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Compilation failed.

So it seems that dart2js looks in the current directory of the dart file to be converted for the packages, which is incorrect.

I tried changing my import statement to import "package:../packages/intl/intl.dart"; but I got the same error.

Does anyone have any ideas?

UPDATE:

I can use pub build to build my project and produce a main.dart.js. Not sure what is different when I call build, perhaps something is wrong with WebStorm?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
shortspider
  • 1,045
  • 15
  • 34

2 Answers2

1

dart2js is not a recommended workflow and can be buggy in WebStorm 8. It is completely removed from the context menu in the upcoming WebStorm 9. Use 'pub build'.

Alexander Doroshko
  • 1,831
  • 13
  • 10
0

I can't see anything wrong. I think this is one of the cases where only

pub cache repair

can help.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • What are you using dart2js for anyway? use `pub build` for transpiling to JavaScript. – Günter Zöchbauer Sep 23 '14 at 04:07
  • Sure I can use `pub build` but should dart2js should work by itself no? – shortspider Sep 23 '14 at 18:16
  • Yes but `dart2js` is a bit more difficult to use (needs several arguments) and `pub build` is super easy and normally does all you want. If `pub build` works and `dart2js` not you have very probably called it from the wrong directory or passed wrong arguments. – Günter Zöchbauer Sep 23 '14 at 18:27