部署到 AWS 时出现错误“意外令牌”<' in flutter.js"

问题描述 投票:0回答:0

我有一个带有 Go 服务器的 Flutter Web 应用程序,通过 AWS CodePipeline(用于 CI/CD)部署到 AWS EC2 实例。我的 EC2 设置是

Go 1 running on 64bit Amazon Linux 2/3.7.2
.

Flutter Web 应用程序在本地服务器上启动时或使用

flutter run --release
命令时可以正常运行。但是,当部署到我的 EC2 实例时,我得到以下空白页面,控制台中显示错误
Uncaught SyntaxError: Unexpected token '<' (at flutter.js:1:1)
(注意:下一个错误,
_flutter is not defined
是由第一个错误引起的)。

奇怪的是,当我查看错误所指的

flutter.js
文件时,该文件显示了错误的内容;它显示了
index.html
文件的内容,正如错误指出的那样,该文件在第 1:1 行确实有一个
<
字符。

下一步,我查看我的 EC2 实例(通过 SSH)以查看我部署的

flutter.js
文件。部署的文件是正确的,不是控制台错误指出的那个。

那么这里发生了什么?这是将 Flutter Web 应用程序部署到 AWS Go 服务器的设置问题还是兼容性问题?如果有任何帮助,下面是完整的 index.html 文件。

注意:我无法在 SO 或其他地方发布的其他类似问题中找到解决方案。

index.html

<!DOCTYPE html>
<html>
<head>
    <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    For more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

    This is a placeholder for base href that will be replaced by the value of
    the `--base-href` argument provided to `flutter build`.
  -->
  <base href="/">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="test_app_1">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png"/>

  <title>test_app_1</title>
  <link rel="manifest" href="manifest.json">

  <script>
    // The value below is injected by flutter build, do not touch.
    var serviceWorkerVersion = null;
  </script>
  <!-- This script adds the flutter initialization JS code -->
  <script src="flutter.js" defer></script>
</head>
<body>
  <script>
    window.addEventListener('load', function(ev) {
      _flutter.loader.loadEntrypoint({
        entrypointUrl: "/main.dart.js",
        serviceWorker: {
          serviceWorkerVersion: serviceWorkerVersion,
          serviceWorkerUrl: "/flutter_service_worker.js?v=",
        },
        onEntrypointLoaded: function(engineInitializer) {
          engineInitializer.initializeEngine().then(function(appRunner) {
            appRunner.runApp();
          });
        }
      });
    });
  </script>
</body>
</html>
flutter amazon-web-services go amazon-ec2 amazon-elastic-beanstalk
© www.soinside.com 2019 - 2024. All rights reserved.