部署到heroku:未捕获的语法错误:意外的令牌<

2024-03-02

我已将mean stack api Angular 6部署到heroku,当我在浏览器上打开应用程序时,它会显示品牌页面,

在我的 server.js 中,这就是我所拥有的

const express = require('express');
const path = require('path');
const flash = require('connect-flash');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const db = require('./app/config/database');

// Connect To Database
mongoose.connect(db.database);

// On Connection
mongoose.connection.on('connected', () => {
  console.log('Connected to database '+db.database);
});

// On Error
mongoose.connection.on('error', (err) => {
  console.log('Database error: '+err);
});

const app = express();

const movies = require('./app/routes/movies');

// Port Number
const port = process.env.PORT || 8000

// CORS Middleware
app.use(cors());

// Set Static Folder
app.use(express.static(path.join(__dirname, '/movies-client/dist')));

// Body Parser Middleware
app.use(bodyParser.json());

app.use('/movies', movies);

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname + '/movies-client/dist/movies-client/index.html'));
});
// Start Server
app.listen(port, () => {
  console.log('Server started on port '+port);
});

当我跑步时heroku logs,这就是我所拥有的

2018-06-20T11:27:14.549707+00:00 heroku[router]: at=info method=GET path="/" host=damp-reef-60581.herokuapp.com request_id=f44c5f42-2bd0-42de-8a5d-18551c306fd0 fwd="212.91.22.46" dyno=web.1 connect=0ms service=50ms status=200 bytes=1191 protocol=https
2018-06-20T11:27:15.041658+00:00 heroku[router]: at=info method=GET path="/runtime.js" host=damp-reef-60581.herokuapp.com request_id=197ccaba-2fa8-42d6-8293-bc481fdf3fc3 fwd="212.91.22.46" dyno=web.1 connect=0ms service=16ms status=200 bytes=1191 protocol=https
2018-06-20T11:27:15.313302+00:00 heroku[router]: at=info method=GET path="/styles.js" host=damp-reef-60581.herokuapp.com request_id=46f87c24-9a16-4d45-82e0-295b184dceec fwd="212.91.22.46" dyno=web.1 connect=0ms service=3ms status=200 bytes=1191 protocol=https
2018-06-20T11:27:16.017486+00:00 heroku[router]: at=info method=GET path="/polyfills.js" host=damp-reef-60581.herokuapp.com request_id=7dd4bb06-ce65-472b-a8d3-106882666a11 fwd="212.91.22.46" dyno=web.1 connect=0ms service=9ms status=200 bytes=1191 protocol=https
2018-06-20T11:27:16.015745+00:00 heroku[router]: at=info method=GET path="/main.js" host=damp-reef-60581.herokuapp.com request_id=1ec5edd6-632d-4b37-9984-fd076fe9a083 fwd="212.91.22.46" dyno=web.1 connect=0ms service=6ms status=200 bytes=1191 protocol=https
2018-06-20T11:27:16.575143+00:00 heroku[router]: at=info method=GET path="/vendor.js" host=damp-reef-60581.herokuapp.com request_id=94178235-0013-49e6-aaa9-d34b84cc78ef fwd="212.91.22.46" dyno=web.1 connect=1ms service=3ms status=200 bytes=1191 protocol=https

当我检查浏览器时,显示此错误:

Uncaught SyntaxError: Unexpected token <
polyfills.js:1 Uncaught SyntaxError: Unexpected token <
styles.js:1 Uncaught SyntaxError: Unexpected token <
vendor.js:1 Uncaught SyntaxError: Unexpected token <
main.js:1 Uncaught SyntaxError: Unexpected token <

structre of the client app where I have dist files enter image description here

为什么我会收到此错误?我该如何解决这个问题?任何帮助或建议都会有帮助


只是为了开始调试您的应用程序,请尝试用斜杠替换通配符,因为通配符可以覆盖/movies route

也许是你的道路

 app.use(express.static(path.join(__dirname, '/movies-client/dist')));

似乎是错误的

 app.use(express.static(path.join(__dirname, '/movies-client/dist/movies-client')));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

部署到heroku:未捕获的语法错误:意外的令牌< 的相关文章

随机推荐

  • 通过 C/C++ 程序使 LED 闪烁的步骤?

    通过 C C 程序制作带有 LED 闪光灯的小电路的最简单步骤是什么 我希望所需的依赖项和包数量最少 我应该将某些东西连接到哪个端口 我会使用哪个编译器 如何将数据发送到该端口 我需要微处理器吗 如果不是 我不想在这个简单的项目中使用它 编
  • 在 Jenkinsfile 中设置 SonarQube Webhook

    我正在尝试创建一个 Jenkins 多分支管道 在每次推送到 bitbucket 时 都会对项目的该分支执行 SonarQube 分析 Jenkins 正确地为每个分支创建新作业 并在 SonarQube 中创建一个新项目 并将分支名称附加
  • 表面和纹理之间的差异(SDL/一般)

    谁能用简单的语言向我解释一下纹理和表面有什么区别 我看到它用在SDL2 as SDL Surface and SDL Texture SDL Texture是从创建的SDL Surface它又是从图像 位图创建的 两者都是像素的集合 但我没
  • 静态 uint8_t 数组的输入过程和类型

    我目前正在尝试将 Arduino IDE 中的整数变量转换为静态 uint8 t 数组的值 我在用 include
  • .NET 如何定位我正在“使用”的命名空间的 dll?

    NET如何定位我所在命名空间的dllusing 是的 我们确实提到了 referene c program files 中的路径 但是在构建和部署之后以及当软件安装在某些用户的计算机上时 它可能与我 开发人员 提到的路径不同 我的意思是它可
  • 如何删除 Rails 中的索引

    我发现我的架构中有两个 survey id 列 这给我带来了一些问题 具体来说 我需要删除第二个索引 因为我不希望 Survey id 是唯一的 add index completions survey id name index comp
  • .NET Core IHttpContextAccessor 问题

    我有静态助手类 public static class Current public static string Host get return httpContextAccessor here 如何访问 Host 属性中的当前 HttpC
  • 在Lua中注册C++函数?

    我正在尝试在 Lua 中注册一个 C 函数 但出现此错误 CScript cpp 39 error argument of type int CScript lua State does not match int lua State ED
  • 为什么 requirejs 尝试加载 .map?

    我正在尝试从 CDN 具体来说是 cdnjs 加载脚本 并且在 requirejs 中您必须像这样保留扩展名 require config baseUrl static js paths underscore cdnjs cloudflar
  • 使用 Active Record & Rails ORDER BY 有时为空的列

    在我的 Rails 应用程序 使用 postgresql 中 我尝试编写一个 Active Record 查询来查找一组志愿者记录 然后按以下顺序对它们进行排序first name then last name then email 此外
  • 如何获取ARN(亚马逊资源名称)?

    我正在尝试使用 AWS 资源标记 API Net 将标签添加到 AWS 资源 我遇到的问题是 Tagging API 使用ARNs作为资源的标识符 但是当我下载资源时 我拥有的唯一 Id 是 InstanceId 有没有一种方法 基于Ins
  • c++0x std::shared_ptr 与 boost::shared_ptr

    我有一个大量使用的 C 代码shared ptr和STL 一个常见的标题说 include
  • 模块和ajax调用

    我正在尝试创建对自定义控制器的 ajax 调用 我一直在关注 http www atwix com magento ajax requests in magento http www atwix com magento ajax reque
  • 在 Flask 中捕获 500 服务器错误

    我喜欢 Flask 的错误捕获功能 它非常简单 app errorhandler 404 def pageNotFound error return page not found 就像魅力一样起作用 但它不适用于 500 错误代码 我想在代
  • ValueInjecter:如何在执行 .InjectFrom(data) 时忽略某些属性?

    我使用 ValueInjecter 而不是 AutoMapper 我正在尝试使用执行展开操作 InjectFrom
  • 命名查询、本机查询或查询从性能角度来看,哪一个更好?

    以下哪一个更好 EJB 3 JPA Query a getEntityManager createQuery 从用户o中选择o 命名查询 其中 findAllUser 在实体级别定义 b getEntityManager createNam
  • 在 R Shiny 中的绘图顶部显示 X 轴而不是底部?

    如何在 Plotly 水平条形图的顶部而不是底部显示 x 轴 在顶部和底部显示 x 轴也可以 绘图将在 R Shiny 中显示 并且必须是 Plotly 而不是 ggplotly 谢谢 示例来自https plot ly r horizo
  • 在 WPF 中显示 HTML 的 TextBlock

    是否有办法将 HTML 从字符串变量显示到 WPF 中的 TextBlock 也许你可以用这个WPF Html 支持的 TextBlock https www codeproject com Articles 33196 WPF Html
  • 在 Razor 中显示 HTML 5 电话号码链接

    我有以下问题 我希望在我的 HTML5 网页上有一个可点击的电话号码 通常我会简单地使用 a href 123456789 a 但就我而言 我从数据库获取号码并访问该号码 现在代码行看起来像这样 a href Html DisplayFor
  • 部署到heroku:未捕获的语法错误:意外的令牌<

    我已将mean stack api Angular 6部署到heroku 当我在浏览器上打开应用程序时 它会显示品牌页面 在我的 server js 中 这就是我所拥有的 const express require express cons