[GIS] ArcGIS API for JS Error message: Uncaught SyntaxError: Unexpected token <

arcgis-javascript-apiarcgis-server

I had created a application using ArcGIS API for JS to geolocate features in the feature layer that is added to basemap. I have an external Javascript and css file that are referenced (called) to html file. When I tried to run the html from web server it is sending an error message (script.js:1 Uncaught SyntaxError: Unexpected token <) for first line of JS file.

I re-checked my scripts couple of times, but I couldn't find any mistake in it. Is there anything wrong with Javascript syntax? Please check the below scripts:

JS:

<script src="https://js.arcgis.com/3.15/"></script>

<script>
var map;

require([
    "esri/map",
    "esri/layers/FeatureLayer",
    "esri/dijit/Search",
     "dojo/domReady!",
    ], 

function(Map, FeatureLayer, Search) {       
    map = new Map("mapDiv", {       
        basemap: "streets",        
        center: [-56.049, 38.485],
        zoom: 3,
    });

    var Search = new Search({
        allPlaceHolder: "Find by address",    
        autoNavigate: false,
        autoSelect: false,
        enableHighlight: true,
        enableInfoWindow: true,
        enableSearchingAll: true,
        map:mapDiv,
        showInfoWindowOnSelect: true,
        theme:arcgisSearch,
        zoomScale:1000
   },"Address"); });

</script>

HTML

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>Geolocating parcels</title>
<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/3.15/esri/css/esri.css">
    <link rel="stylesheet" type="text/css" href="https://js.arcgis.com/3.15/dijit/themes/claro/claro.css">
    <script src="https://js.arcgis.com/3.15/"></script>
    <link rel ="stylesheet" href ="styles.css">
</head>

  <body>
  <div id = "mapDiv" style="position: relative; width:50px; height:50px; border:1px solid #000;"></div>
  <div id = "Address">  </div>  

  <script src="script.js" type ="text/javascript" ></script>
  <script src="https://js.arcgis.com/3.15/"></script>
  </body>
</html>

Best Answer

  1. You're calling <script src="https://js.arcgis.com/3.15/"></script> multiple times in your HTML file.
  2. You can't use <script> HTML tags inside your .js file.
Related Question