Angular app compiling correctly, but it is not loading
I'm building an app with Angular 6, and now I want to serve it using ExpressJS.
For this, I went on to compile the app using ng serve --prod
, but the app was not loading, as I was getting SyntaxError: expected expression, got '<'
in the console.
I thought that maybe something was wrong with my app, but it was working fine with ng serve
, so I tried with ng serve --prod
, and everything worked flawlessly still.
Then I decided to try with just ng build
(no --prod
), and got the same error.
In GitHub issues I found some related stuff, but were specific to some packages and older versions of angular.
This is my package.json, in case it is relevant:
{
"name": "mt",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/cdk": "^6.4.7",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/material": "^6.4.7",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"core-js": "^2.5.4",
"d3": "^5.7.0",
"dateformat": "^3.0.3",
"rxjs": "~6.2.0",
"xlsx": "^0.14.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.8.0",
"@angular/cli": "~6.2.1",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.3.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~2.9.2"
}
}
I suposse the problem is not with my code per se, as the app is working fine with the ng serve
command, with or without the --prod
flag.
Any ideas on how to solve this issue?
EDIT: This is my express file to serve the app
const html = __dirname + '/dist/';
const port = 4200;
// Express
const bodyParser = require('body-parser');
const compression = require('compression');
const express = require('express');
var app = express();
app
.use(compression())
.use(bodyParser.json())
// Static content
.use(express.static(html))
// Start server
.listen(port, function () {
console.log('Port: ' + port);
console.log('Html: ' + html);
});
app.get('*', function(req, res) {
res.sendfile('./dist/mtloops-web-app/index.html');
});
angular
|
show 2 more comments
I'm building an app with Angular 6, and now I want to serve it using ExpressJS.
For this, I went on to compile the app using ng serve --prod
, but the app was not loading, as I was getting SyntaxError: expected expression, got '<'
in the console.
I thought that maybe something was wrong with my app, but it was working fine with ng serve
, so I tried with ng serve --prod
, and everything worked flawlessly still.
Then I decided to try with just ng build
(no --prod
), and got the same error.
In GitHub issues I found some related stuff, but were specific to some packages and older versions of angular.
This is my package.json, in case it is relevant:
{
"name": "mt",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/cdk": "^6.4.7",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/material": "^6.4.7",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"core-js": "^2.5.4",
"d3": "^5.7.0",
"dateformat": "^3.0.3",
"rxjs": "~6.2.0",
"xlsx": "^0.14.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.8.0",
"@angular/cli": "~6.2.1",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.3.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~2.9.2"
}
}
I suposse the problem is not with my code per se, as the app is working fine with the ng serve
command, with or without the --prod
flag.
Any ideas on how to solve this issue?
EDIT: This is my express file to serve the app
const html = __dirname + '/dist/';
const port = 4200;
// Express
const bodyParser = require('body-parser');
const compression = require('compression');
const express = require('express');
var app = express();
app
.use(compression())
.use(bodyParser.json())
// Static content
.use(express.static(html))
// Start server
.listen(port, function () {
console.log('Port: ' + port);
console.log('Html: ' + html);
});
app.get('*', function(req, res) {
res.sendfile('./dist/mtloops-web-app/index.html');
});
angular
The problem is probably in how you serve the application. Tell us precisely how you do that.
– JB Nizet
Dec 28 '18 at 18:14
Added an edit with the file in which I'm serving the app with Express
– Maximiliano Andres Friedl Schw
Dec 28 '18 at 20:10
1
I don't know much about express, but my guess is that html should be__dirname + '/dist/mtloops-web-app/'
.
– JB Nizet
Dec 28 '18 at 20:16
That didn't work. The express server is "serving" the app correctly, the problem is the app is not loading and throwing theSyntaxError: expected expression, got '<'
in console. When the server doesn't recognize theindex.html
file it throws an error on screen saying the file was not found.
– Maximiliano Andres Friedl Schw
Dec 29 '18 at 16:10
1
which probably means that your server sends an HTML file when the browser requests a JS file. Look at your network panel in the dev tools to see what requests are made and what responses are received.
– JB Nizet
Dec 29 '18 at 16:46
|
show 2 more comments
I'm building an app with Angular 6, and now I want to serve it using ExpressJS.
For this, I went on to compile the app using ng serve --prod
, but the app was not loading, as I was getting SyntaxError: expected expression, got '<'
in the console.
I thought that maybe something was wrong with my app, but it was working fine with ng serve
, so I tried with ng serve --prod
, and everything worked flawlessly still.
Then I decided to try with just ng build
(no --prod
), and got the same error.
In GitHub issues I found some related stuff, but were specific to some packages and older versions of angular.
This is my package.json, in case it is relevant:
{
"name": "mt",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/cdk": "^6.4.7",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/material": "^6.4.7",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"core-js": "^2.5.4",
"d3": "^5.7.0",
"dateformat": "^3.0.3",
"rxjs": "~6.2.0",
"xlsx": "^0.14.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.8.0",
"@angular/cli": "~6.2.1",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.3.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~2.9.2"
}
}
I suposse the problem is not with my code per se, as the app is working fine with the ng serve
command, with or without the --prod
flag.
Any ideas on how to solve this issue?
EDIT: This is my express file to serve the app
const html = __dirname + '/dist/';
const port = 4200;
// Express
const bodyParser = require('body-parser');
const compression = require('compression');
const express = require('express');
var app = express();
app
.use(compression())
.use(bodyParser.json())
// Static content
.use(express.static(html))
// Start server
.listen(port, function () {
console.log('Port: ' + port);
console.log('Html: ' + html);
});
app.get('*', function(req, res) {
res.sendfile('./dist/mtloops-web-app/index.html');
});
angular
I'm building an app with Angular 6, and now I want to serve it using ExpressJS.
For this, I went on to compile the app using ng serve --prod
, but the app was not loading, as I was getting SyntaxError: expected expression, got '<'
in the console.
I thought that maybe something was wrong with my app, but it was working fine with ng serve
, so I tried with ng serve --prod
, and everything worked flawlessly still.
Then I decided to try with just ng build
(no --prod
), and got the same error.
In GitHub issues I found some related stuff, but were specific to some packages and older versions of angular.
This is my package.json, in case it is relevant:
{
"name": "mt",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/cdk": "^6.4.7",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/material": "^6.4.7",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"core-js": "^2.5.4",
"d3": "^5.7.0",
"dateformat": "^3.0.3",
"rxjs": "~6.2.0",
"xlsx": "^0.14.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.8.0",
"@angular/cli": "~6.2.1",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.3.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~2.9.2"
}
}
I suposse the problem is not with my code per se, as the app is working fine with the ng serve
command, with or without the --prod
flag.
Any ideas on how to solve this issue?
EDIT: This is my express file to serve the app
const html = __dirname + '/dist/';
const port = 4200;
// Express
const bodyParser = require('body-parser');
const compression = require('compression');
const express = require('express');
var app = express();
app
.use(compression())
.use(bodyParser.json())
// Static content
.use(express.static(html))
// Start server
.listen(port, function () {
console.log('Port: ' + port);
console.log('Html: ' + html);
});
app.get('*', function(req, res) {
res.sendfile('./dist/mtloops-web-app/index.html');
});
angular
angular
edited Dec 28 '18 at 20:10
Maximiliano Andres Friedl Schw
asked Dec 28 '18 at 18:06
Maximiliano Andres Friedl SchwMaximiliano Andres Friedl Schw
529
529
The problem is probably in how you serve the application. Tell us precisely how you do that.
– JB Nizet
Dec 28 '18 at 18:14
Added an edit with the file in which I'm serving the app with Express
– Maximiliano Andres Friedl Schw
Dec 28 '18 at 20:10
1
I don't know much about express, but my guess is that html should be__dirname + '/dist/mtloops-web-app/'
.
– JB Nizet
Dec 28 '18 at 20:16
That didn't work. The express server is "serving" the app correctly, the problem is the app is not loading and throwing theSyntaxError: expected expression, got '<'
in console. When the server doesn't recognize theindex.html
file it throws an error on screen saying the file was not found.
– Maximiliano Andres Friedl Schw
Dec 29 '18 at 16:10
1
which probably means that your server sends an HTML file when the browser requests a JS file. Look at your network panel in the dev tools to see what requests are made and what responses are received.
– JB Nizet
Dec 29 '18 at 16:46
|
show 2 more comments
The problem is probably in how you serve the application. Tell us precisely how you do that.
– JB Nizet
Dec 28 '18 at 18:14
Added an edit with the file in which I'm serving the app with Express
– Maximiliano Andres Friedl Schw
Dec 28 '18 at 20:10
1
I don't know much about express, but my guess is that html should be__dirname + '/dist/mtloops-web-app/'
.
– JB Nizet
Dec 28 '18 at 20:16
That didn't work. The express server is "serving" the app correctly, the problem is the app is not loading and throwing theSyntaxError: expected expression, got '<'
in console. When the server doesn't recognize theindex.html
file it throws an error on screen saying the file was not found.
– Maximiliano Andres Friedl Schw
Dec 29 '18 at 16:10
1
which probably means that your server sends an HTML file when the browser requests a JS file. Look at your network panel in the dev tools to see what requests are made and what responses are received.
– JB Nizet
Dec 29 '18 at 16:46
The problem is probably in how you serve the application. Tell us precisely how you do that.
– JB Nizet
Dec 28 '18 at 18:14
The problem is probably in how you serve the application. Tell us precisely how you do that.
– JB Nizet
Dec 28 '18 at 18:14
Added an edit with the file in which I'm serving the app with Express
– Maximiliano Andres Friedl Schw
Dec 28 '18 at 20:10
Added an edit with the file in which I'm serving the app with Express
– Maximiliano Andres Friedl Schw
Dec 28 '18 at 20:10
1
1
I don't know much about express, but my guess is that html should be
__dirname + '/dist/mtloops-web-app/'
.– JB Nizet
Dec 28 '18 at 20:16
I don't know much about express, but my guess is that html should be
__dirname + '/dist/mtloops-web-app/'
.– JB Nizet
Dec 28 '18 at 20:16
That didn't work. The express server is "serving" the app correctly, the problem is the app is not loading and throwing the
SyntaxError: expected expression, got '<'
in console. When the server doesn't recognize the index.html
file it throws an error on screen saying the file was not found.– Maximiliano Andres Friedl Schw
Dec 29 '18 at 16:10
That didn't work. The express server is "serving" the app correctly, the problem is the app is not loading and throwing the
SyntaxError: expected expression, got '<'
in console. When the server doesn't recognize the index.html
file it throws an error on screen saying the file was not found.– Maximiliano Andres Friedl Schw
Dec 29 '18 at 16:10
1
1
which probably means that your server sends an HTML file when the browser requests a JS file. Look at your network panel in the dev tools to see what requests are made and what responses are received.
– JB Nizet
Dec 29 '18 at 16:46
which probably means that your server sends an HTML file when the browser requests a JS file. Look at your network panel in the dev tools to see what requests are made and what responses are received.
– JB Nizet
Dec 29 '18 at 16:46
|
show 2 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962588%2fangular-app-compiling-correctly-but-it-is-not-loading%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962588%2fangular-app-compiling-correctly-but-it-is-not-loading%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The problem is probably in how you serve the application. Tell us precisely how you do that.
– JB Nizet
Dec 28 '18 at 18:14
Added an edit with the file in which I'm serving the app with Express
– Maximiliano Andres Friedl Schw
Dec 28 '18 at 20:10
1
I don't know much about express, but my guess is that html should be
__dirname + '/dist/mtloops-web-app/'
.– JB Nizet
Dec 28 '18 at 20:16
That didn't work. The express server is "serving" the app correctly, the problem is the app is not loading and throwing the
SyntaxError: expected expression, got '<'
in console. When the server doesn't recognize theindex.html
file it throws an error on screen saying the file was not found.– Maximiliano Andres Friedl Schw
Dec 29 '18 at 16:10
1
which probably means that your server sends an HTML file when the browser requests a JS file. Look at your network panel in the dev tools to see what requests are made and what responses are received.
– JB Nizet
Dec 29 '18 at 16:46