-2

My angular build is throwing this in web browser. Uncaught SyntaxError: expected expression, got '<' in bundle.js

I am running this command npm run dev:ssr, and it generates no error.

But when I browse the application it displays the error. I tried with ng serve --aot but the application is configured to be run only with npm run dev:ssr. From where I can debug so I can fix this syntax error.

Edit: More Information npm run build makes the bundle.js with correct data in dist/browser. So I think it is some debug feature?

Muhammad Arslan Jamshaid
  • 1,077
  • 8
  • 27
  • 48

1 Answers1

-1

Your browser is looking for bundle.js which is available but your server is sending some other startup file (e.g. index.html) which itself starts with new HTML tag (e.g. <!DOCTYPE html> etc.) .

So when javascript parses your bundle.js file, it was looking for expression (e.g. methods, function body of typescript etc.), but it got new HTML start tag <. This scenario resulted in Uncaught SyntaxError: expected expression, got '<'.

So can you check source of your page (under Sources section) in browser if bundle.js has any html tag included. If that is case, you may need change your routing so that either bundle.js will be loaded or other startup file will gets loaded.

Ashish Patil
  • 4,428
  • 1
  • 15
  • 36
  • I understand what it is, thank you for translating it. What I am looking for is, a solution, to track and fix this. – Muhammad Arslan Jamshaid Jul 15 '22 at 15:44
  • `From where I can debug so I can fix this syntax error.` this is what you have asked. Modify your question & share some more details so that anyone can see you are looking for solution & not just direction where to start debugging. Thanks – Ashish Patil Jul 15 '22 at 16:01