部署到heroku:未捕获的SyntaxError:意外的令牌< [英] Deploy to heroku : Uncaught SyntaxError: Unexpected token <
本文介绍了部署到heroku:未捕获的SyntaxError:意外的令牌<的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在浏览器中打开其显示页面的应用程序
I have deployed mean stack api angular 6 to heroku , when I open the app on browser its displays brank page ,
在我的server.js中,这就是我所拥有的
In my server.js this is what i have
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
时,这就是我所拥有的
when I run heroku logs
, this is what I have
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
当我检查浏览器时,显示此错误:
when I inspect the browser this error is shown :
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 <
结构
为什么会出现此错误?以及我该如何解决?任何帮助或建议都会有所帮助
why am I getting this error? and how can I solve it? any help or suggestion will be helpfully
推荐答案
只是为了开始调试您的应用,请尝试用斜杠替换通配符,因为通配符可以覆盖/movies
路由
Just for start debugging your app try to replace wildcard by a slash because wildcard can override /movies
route
也许是你的路途
app.use(express.static(path.join(__dirname, '/movies-client/dist')));
似乎是错误的
app.use(express.static(path.join(__dirname, '/movies-client/dist/movies-client')));
这篇关于部署到heroku:未捕获的SyntaxError:意外的令牌<的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文