dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.24k stars 1.57k forks source link

`dart create -t web-simple ...` creates app that 500s #47742

Open leighmcculloch opened 2 years ago

leighmcculloch commented 2 years ago

Creating a new dart application using the web-simple template using the dart cli, results in an application that 500s with errors. It seems like the template has been broken in some way.

$ dart create -t web-simple testapp
$ dart pub global activate webdev
$ webdev serve

Visiting https://127.0.0.1:8080 displays a blank page with console errors:

[Error] Failed to load resource: the server responded with a status of 500 (Internal Server Error) (main.dart.bootstrap.js, line 0)
[Error] Refused to execute http://localhost:8080/@http://localhost:8080/main.dart.bootstrap.js as script because "X-Content-Type-Options: nosniff" was given and its Content-Type is not a script MIME type.
[Error] Error: Script error for "main.dart.bootstrap"
http://requirejs.org/docs/errors.html#scripterror
    defaultOnError (require.js:143)
    onError (require.js:549)
    onScriptError (require.js:1738)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (stack_trace_mapper.dart.js.map, line 0)

The server displays the following errors in the logs:

[INFO] There was output on stdout while compiling the build script snapshot, run with `--verbose` to see it (you will need to run a `clean` first to re-snap[INFO] Building new asset graph completed, took 968ms
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[INFO] Serving `web` on http://127.0.0.1:8080
[INFO] Generating SDK summary completed, took 2.8s
[INFO] Running build completed, took 6.0s
[INFO] Caching finalized dependency graph completed, took 180ms
[INFO] Succeeded after 6.2s with 14 outputs (1293 actions)
[INFO] ----------------------------------------------------------------------------------------------------------------------------------------------------
ERROR - 2021-11-20 15:16:52.422153
GET /@http://127.0.0.1:8080/main.dart.bootstrap.js
Error thrown by handler.
FormatException: Scheme not starting with alphabetic character (at character 1)
@http://127.0.0.1:8080/main.dart.bootstrap.js
^

dart:core                                   _SimpleUri.resolve
package:shelf_proxy/shelf_proxy.dart 42:28  proxyHandler.<fn>
package:shelf_proxy/shelf_proxy.dart 37:10  proxyHandler.<fn>
muzuro commented 2 years ago

I have similar issue. I have built dart web app, deployed it to firebase hosting but it don't works at safari. It fails with 404 when main.dart.bootstrap.js is loaded. Here is request summary from safari console:

URL: https://host.com/@https://host.com/main.dart.bootstrap.js
URL: https://host.com/@https:/host.com/main.dart.bootstrap.js
Status: 404
Source: Network
Initiator:
require.js:1959
muzuro commented 2 years ago

For some reasons there is "@" prefix before url in data-main attribute for script tag to import main.dart.bootstrap. image

Interesting that in chrome this import looks different: <script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="main.dart.bootstrap" src="https://dashboard.qvin.com/main.dart.bootstrap.js"></script>

muzuro commented 2 years ago

I think reason was development JavaScript compiler. I changed build script to webdev build and it started to work fine.

arnaud-secondlayer commented 1 year ago

Any progress on this issue? It's quite difficult to work on OSX and test locally with safari right now

vakechu commented 1 year ago

I found the reason for "@" prefix in Safari - build_web_compilers/lib/src/dev_compiler_bootstrap.dart, function _currentDirectoryScript. Changing return statement for Safari to:

return lines[0].match(/(.+):\d+:\d+$/)[1].substring(1);

solves the problem, but it's more of a quick fix.