在 Heroku 上部署 Angular2 会在所有外部引用上产生'Uncaught SyntaxError: Unexpected Token <'



我正在尝试在Heroku上部署Angular4应用程序。但是我在.html链接的所有.js引用中都会出现错误。

错误就是这样

16:29:54.613 myapp.herokuapp.com/:1 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://myapp.herokuapp.com/assets/style/bootstrap.css".
16:29:54.646 jquery-1.10.2.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.647 myapp.herokuapp.com/:1 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://myapp.herokuapp.com/styles.d41d8cd98f00b204e980.bundle.css".
16:29:54.685 bootstrap.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.743 jquery.bxslider.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.744 jquery.centralized.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.776 jquery.fixedonlater.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.865 jquery.hashloader.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.867 jquery.mixitup.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.868 jquery.nav.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.869 jquery.parallax-1.1.3.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.946 jquery.responsivevideos.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.947 jquery.scrollTo.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.948 jquery.tweet.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:54.999 jquery.tweetCarousel.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:55.001 holder.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:55.003 application.min.js:1 Uncaught SyntaxError: Unexpected token <
16:29:55.005 inline.230e19a62ca0cc6cf333.bundle.js:1 Uncaught SyntaxError: Unexpected token <
16:29:55.007 polyfills.2a6cee40ee8af30fbaec.bundle.js:1 Uncaught SyntaxError: Unexpected token <
16:29:55.018 vendor.20becde8ac8acd1f3058.bundle.js:1 Uncaught SyntaxError: Unexpected token <
16:29:55.019 main.f037d06044d7934ea073.bundle.js:1 Uncaught SyntaxError: Unexpected token <

所有这些文件都存在于我的src/client/assets/js/目录中。

我的server.js就是这样

const express = require('express');
const path = require('path');
const root = './dist/public';
const pub = process.env.PUBLIC || `${root}`;
const app = express();
app.use(express.static(path.join(__dirname, 'dist/public/assets')));
app.use(express.static(path.join(__dirname, 'dist/public')));
app.get('/*', (req, res) => {
    res.sendFile(`index.html`, { root: pub });
});
const port = process.env.PORT || 3000;
app.set('port', port);
app.listen(port, () => console.log(`API running on localhost:${port}`));

我想念什么吗?该应用程序在本地工作正常。

这与我的dyno在哪里执行脚本的文件位置有关。我的server.js"静态上使用"的所有文件都需要相对于server.js

相关内容

最新更新