在Heroku上部署Angular2会产生' Uncaught SyntaxError:意外的令牌<'在所有外部参考

时间:2017-09-09 23:53:00

标签: node.js angular express heroku

我试图在Heroku上部署angular4应用程序。但是,我从.js链接的所有.html个引用都出现了错误。

错误就是这样

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}`));

我错过了什么吗?该应用程序在本地工作正常。

1 个答案:

答案 0 :(得分:0)

这与我的dyno执行脚本的位置的文件位置有关。我server.js所提供的所有“静态”文件都需要相对于server.js引用。