Issue
I’m trying to get my dummy Dart webapp running in browsers. Here’s the code of my html page:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<!-- Always force latest IE rendering engine or request Chrome Frame -->
<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
</head>
<body>
<div id='button'>hello world</div>
</body>
<script src='my_app.dart' type='application/dart'></script>
<script src='packages/browser/dart.js'></script>
</html>
and this is what I’m getting in js console when trying to open it:
GET http://localhost:4567/my_app.dart.js 404 (Not Found)
(I’m running it on a local server, thus the url – got the same error if simply opening an html file though).
If I open the same url in Dartium, the webapp works. So the problem, I suppose, is that dart.js
doesn’t work as expected. What could be the problem?
Solution
packages/browser/dart.js
is a bootstrap script that checks if a Dart VM is available on your browser. If a Dart VM is available, your dart script is executed directly, otherwise packages/browser/dart.js
appends to the document a new js script with a url that points to a file with the same name as your dart file but with a appended .js
. Depending on how you work you may have to generate this JS file manually with dart2js :
dart2js --out=my_app.dart.js my_app.dart
Answered By – Alexandre Ardhuin
Answer Checked By – Jay B. (FlutterFixes Admin)