[javascript] Unexpected token < in first line of HTML

I have an HTML file :

<!DOCTYPE HTML>
<html lang="en-US" ng-app="Todo">
<head>
    <meta charset="UTF-8">
    <title>DemoAPI</title>

  <meta name="viewport">

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>

<link rel="stylesheet" href="./Client/css/styling.css" />
<script type="text/javascript" src="core.js"></script>

</head>

The error says:

Uncaught SyntaxError: Unexpected token <    core.js: 1

It shows the error at <!doctype html> of the app.html.

core.js looks like this:

angular.module('Todo', [])

.controller('mainController', function($scope, $http)
{
    $scope.formData = {};

    // get all and show them
    $http.get('/musicians')
        .success(function(data) {
            $scope.todos = data;
            console.log(data);
        })
        .error(function(data) {
            console.log('Error: ' + data);
        });

        //get with an id
        $scope.getOneTodo = function() {
        $http.get('/musicians' + id)
            .success(function(data) {
                $scope.todos = data;
                      console.log(data);
            })
            .error(function(data) {
                console.log('Error: ' + data);
            });
    };
      // send the text to the node API
    $scope.createTodo = function() {
        $http.post('/musicians', $scope.formData)
            .success(function(data) {
                $scope.formData = {}; // clear the form 
                $scope.todos = data;
                console.log(data);
            })
            .error(function(data) {
                console.log('Error: ' + data);
            })
    };

    // delete 
    $scope.deleteTodo = function(id) {
        $http.delete('/musicians' + id)
            .success(function(data) {
                $scope.todos = data;
                      console.log(data);
            })
            .error(function(data) {
                console.log('Error: ' + data);
            });
    };

    /*
    $scope.updateTodo = function(id) {
        $http.delete('/musicians' + id)
            .success(function(data) {
                $scope.todos = data;
                      console.log(data);
            })
            .error(function(data) {
                console.log('Error: ' + data);
            });
    };*/

});

It also gives me Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.14/$injector/modulerr?p0=Todo&p1=Error%3A%2…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A17%3A381)

Besides, in console, when I click at core.js, it shows the contents of app.html and name it core.js.

Here is the snapshot:

Showing app.html instead of core.js

Also, as in the image, when I click index.html, it shows app.html. However, I do not have any file that is named index.html and I load app.html by default instead of index.html.

I have tried adding/removing type="text/javascript" but no help with that either.

Also, status 200 is returned on get request for core.js.

Status: 200

What might be wrong?

The answer is


Check your encoding, i got something similar once because of the BOM.

Make sure the core.js file is encoded in utf-8 without BOM


I had the same issue. I published the angular/core application on iis.

To change the Identity of the application pool solved my issue. Now the Identity is LocalSystem


Well... I flipped the internet upside down three times but did not find anything that might help me because it was a Drupal project rather than other scenarios people described.

My problem was that someone in the project added a js which his address was: <script src="http://base_url/?p4sxbt"></script> and it was attached in this way:

drupal_add_js('',
    array('scope' => 'footer', 'weight' => 5)
  );

Hope this will help someone in the future.


I experienced this error with my WordPress site but I saw that there were two indexes showing in my developer tools sources.

Chrome Developer Tool Error So I had the thought that if there are two indexes starting at the first line of code then there's a replication and they're conflicting with each other. So I thought that then perhaps it's my HTML minification from my caching plugin tool.

So I turned off the HTML minify setting and deleted my cache. And poof! It worked!


In my case I got this error because of a line

<script src="#"></script> 

Chrome tried to interpret the current HTML file then as javascript.


We had the same problem sometime ago where a site suddenly began giving this error. The reason was that a js include was temporarily remarked with a # (i.e. src="#./js...").


For me this was a case that the Script path wouldn't load - I had incorrectly linked it. Check your script files - even if no path error is reported - actually load.


I had this problem in an ASP.NET application, specifically a Web Forms.

I was forcing a redirect in Global.asax, but I forgot to check if the request was for resources like css, javascript, etc. I just had to add the following checks:

VB.NET

If Not Response.IsRequestBeingRedirected _
    And Not Request.Url.AbsoluteUri.Contains(".WebResource") _
    And Not Request.Url.AbsoluteUri.Contains(".css") _
    And Not Request.Url.AbsoluteUri.Contains(".js") _
    And Not Request.Url.AbsoluteUri.Contains("images/") _
    And Not Request.Url.AbsoluteUri.Contains("favicon") Then
        Response.Redirect("~/change-password.aspx")
End If

I was forcing logged users which hadn't change their passwords for a long time, to be redirected to the change-password.aspx page. I believe there is a better way to check this, but for now, this worked. Should I find a better solution, I edit my answer.


Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to angularjs

AngularJs directive not updating another directive's scope ERROR in Cannot find module 'node-sass' CORS: credentials mode is 'include' CORS error :Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400 Print Html template in Angular 2 (ng-print in Angular 2) $http.get(...).success is not a function Angular 1.6.0: "Possibly unhandled rejection" error Find object by its property in array of objects with AngularJS way Error: Cannot invoke an expression whose type lacks a call signature

Examples related to syntax-error

Uncaught SyntaxError: Unexpected token u in JSON at position 0 How to solve SyntaxError on autogenerated manage.py? Checking whether the pip is installed? (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape How can you print multiple variables inside a string using printf? Unexpected token < in first line of HTML Laravel: Error [PDOException]: Could not Find Driver in PostgreSQL 'Syntax Error: invalid syntax' for no apparent reason How can I fix MySQL error #1064? Notice: Trying to get property of non-object error

Examples related to uncaught-exception

Unexpected token < in first line of HTML