javascriptmean-stack

Uncaught SyntaxError: Unexpected token < on each js file that invoked in the index html


I am using mean stack to build a website, when testing, chrome returns the error like:

Uncaught SyntaxError: Unexpected token < angular.js:1.

I don't know what's wrong and what should i do.

enter image description here

Here is the directory of my app: E-study -client -app -components -all the libraries are here. -index.html -controllers.js -node_modules -server -config -server.js

And I run the server in E-study like :node server/config/server.js

The scripts in the index.html is<script src="client/components/angular/angular.js"></script>

Just don't know why all the js files are changed to index.html when open in the browser.


Solution

  • open up those library files and see if there are some extra symbol < probably you will find it in the beginning.. if still not able to fix... simply download the fresh library (if those are libraries) from the internet and try again.

    make sure that you don't put <script> </script> tags in the included .js files. that is an incorrect syntax for script files.

    also make sure you are providing the correct path??? providing incorrect path can return a builtin customized error page. which is html. may be that is the source of error because returned page is HTML which is most likely going to start with a < symbol. and offcourse not a js file.

    to ensure that the incorrect path is the issue just copy the path you included in the code and and paste into your favorite browsers url bar and hit enter. if you are not getting the script in plain text.. then it means you are not providing the correct path.

    and if it is return a customized error page like .. 404 not found then probably it is returning the html and this is where the error is coming from.