[Solved] Failing to get Dart's Pub working

I know what I’m doing is unsupported, but maybe someone has ideas on how to make it work anyway? :slight_smile:

I have server-side Dart working fine but to get client-side Dart compiled (or even to just use shared packages on the server) I need pub packages working (pub is Dart’s equiv of npm).

Packages are restored by calling pub get. I can call this from the install hook in package.json and it seems to work fine (output shows it download packages and no errors). By default these packages go into ~/.pub-cache (~ is /app here). However if I list that folder immediately after, it appears empty:

dart-sdk/bin/pub get && ls -la /app/.pub-cache

This is sorta confusing… it’s like /app/.pub-cache is some magic black hole (or Dart failed to report it couldn’t write here, or it put these files elsewhere, both of which are possible, but unexpected… even --verbose doesn’t make it spit the location out to confirm).

So, maybe anything outside /app/src is readonly and pub is just bad at reporting failures? I tried setting PUB_CACHE which the docs say will change the location of the pub cache:

PUB_CACHE=/app/src/.pub-cache && echo $PUB_CACHE && dart-sdk/bin/pub get && ls -la /app/src/.pub-cache

However still, the files aren’t there. Is there something weird with the filesystem here or am I doing something dopey?

Ugh… Why is it that you always figure out what’s wrong as you press Save? :smiley:

I added export to the start of that last command and now I can see them! :slight_smile:

Now to figure out how to get Dart to use the new path at runtime!

It’s the power of putting your thoughts in order for your subconscious :smiley:

We love all the work you have been doing. We are going to work on making what are doing easier - so thank you!

We are all on planes today so expect some radio silence until Monday :slight_smile:

So, after learning a little more about the shell (and the difference between export, env etc) I managed to make this work for both the package restore and dart runtime.

My node script (which downloads and installs Dart) now restores packages like this:

console.log(exec('env PUB_CACHE=/app/src/.pub-cache dart-sdk/bin/pub get'));

And in package.json I kick Dart off like this:

env PUB_CACHE=/app/src/.pub-cache dart-sdk/bin/dart server.dart

This seems to work; my server-side app is now finding pub packages on disk :slight_smile: I do have to edit packages.json if I change pub packages (to trigger pub get with a writeable fs) but if I use dart2js dynamically to compile the client-side scripts, at least they will update immediately.

This is currently in another project, but once I get the client stuff working I’ll pull it back into the simple Dart sample I linked elsewhere.

That’d be great! As fun as it has been abusing node/npm config to run TypeScript and Dart (and I actually mean that; I’ve learned new stuff about node, npm, ts and dart in doing this!) it’s not how I’d choose to run an app for real :wink: