Angular Deployment

I tried to deploy the angular app “followers” to Heroku, when done, the page shows nothing. The log shows error:
Uncaught SyntaxError: Unexpected token ‘<’
polyfills.bf99d438b005d57b2b31.js:1 Uncaught SyntaxError: Unexpected token ‘<’
main.b2ea645c9a6cb4b610ed.js:1

Tried to find what went wrong, haven’t got any idea yet.

And also why do we need to use a server.js in the Angular app for deployment to Heroku? I remember we don’t have this in the React courses.

Just figured it out, it is caused by different of the build output. just changed your server.js to below:

const express = require(“express”);

const app = express();

const path = require(“path”);

app.use(express.static(path.join(__dirname, “dist/hello-world”)));

console.log("@@", path.join(__dirname, “dist/hello-world/index.html”));

// app.all("/*", (_, res) =>

// res.status(200).sendFile(path.join(__dirname, “dist/hello-world/index.html”))

// );

app.listen(process.env.PORT || 8080, () =>

console.log(

`Server is running on http://localhost:${process.env.PORT || 8080} ...`

)

);

howevver, 404 is not working

const express = require(“express”);

const app = express();

const path = require(“path”);

app.use(express.static(path.join(__dirname, “dist/hello-world”)));

app.all("/*", (_, res) =>

res.status(200).sendFile(path.join(__dirname, “dist/hello-world/index.html”))

);

app.listen(process.env.PORT || 8080, () =>

console.log(

`Server is running on http://localhost:${process.env.PORT || 8080} ...`

)

);

works now.

just need to change to app.use(express.static(path.join(__dirname, “dist/hello-world”)));

1 Like