我刚刚尝试将MEVN堆栈应用程序部署到heroku。本地一切正常,但是部署后,我在控制台中得到一个空白页和以下错误:
未捕获的SyntaxError:意外的令牌'<'chunk-vendors.61adafa8.js:1 未捕获到的SyntaxError:意外令牌'<'app.f7decf8d.js:1
我真的不知道该怎么办以及可能出现的问题。
index.js
const path = require('path')
const express = require('express')
const cors = require('cors')
const mongoose = require('mongoose')
const BanksController = require('./controllers/BanksController')
const OfficesController = require('./controllers/OfficesController')
const PORT = process.env.PORT || 3000
mongoose.connect(process.env.DB, { useNewUrlParser: true, useUnifiedTopology: true });
const app = express()
app.use(cors())
app.get('/api/banks', BanksController.index)
app.get('/api/offices', OfficesController.index)
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'dist', 'index.html'))
});
app.listen(PORT, () => console.log('Listening on port ' + PORT))
index.html
<!DOCTYPE html><html lang=bg><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="Справочник на банките и банковите офиси в България"><meta name=author content="Petar Karagenov"><meta name=robots content=index,follow><link rel=stylesheet href=https://js.api.here.com/v3/3.1/mapsjs-ui.css><title>Банкомап</title><link href=/css/app.60d1958f.css rel=preload as=style><link href=/css/chunk-vendors.2d9bb5a9.css rel=preload as=style><link href=/js/app.f7decf8d.js rel=preload as=script><link href=/js/chunk-vendors.61adafa8.js rel=preload as=script><link href=/css/chunk-vendors.2d9bb5a9.css rel=stylesheet><link href=/css/app.60d1958f.css rel=stylesheet></head><body><noscript><strong>We're sorry but client doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=https://js.api.here.com/v3/3.1/mapsjs-core.js charset=utf-8></script><script src=https://js.api.here.com/v3/3.1/mapsjs-service.js charset=utf-8></script><script src=https://js.api.here.com/v3/3.1/mapsjs-mapevents.js charset=utf-8></script><script src=https://js.api.here.com/v3/3.1/mapsjs-ui.js charset=utf-8></script><script src=https://js.api.here.com/v3/3.1/mapsjs-clustering.js charset=utf-8></script><script src=/js/chunk-vendors.61adafa8.js></script><script src=/js/app.f7decf8d.js></script></body></html>
答案 0 :(得分:0)
找到了解决方案。我没有添加中间件...
app.use(express.static(path.join(__dirname, "client", "dist")))