2

I'm trying to use this google maps code in my Express App, but it's giving me a syntaxError. I already filtered the bugs to this function:

  <% var map; %>
  <% function initMap() { %>
  <%  map = new google.maps.Map(document.getElementById('map'), { %>
  <%    center: {lat: -34.397, lng: 150.644}, %>
  <%    zoom: 8 %>
  <%  }); %>
  <% }; %>

The error message doesn't really help a lot:

SyntaxError: Unexpected token ; in C:\proyectos\google-location-api\views\resultados.ejs while compiling ejs

If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
    at Object.compile (C:\proyectos\google-location-api\node_modules\ejs\lib\ejs.js:524:12)
    at Object.compile (C:\proyectos\google-location-api\node_modules\ejs\lib\ejs.js:338:16)
    at handleCache (C:\proyectos\google-location-api\node_modules\ejs\lib\ejs.js:181:18)
    at tryHandleCache (C:\proyectos\google-location-api\node_modules\ejs\lib\ejs.js:203:14)
    at View.exports.renderFile [as engine] (C:\proyectos\google-location-api\node_modules\ejs\lib\ejs.js:412:10)
    at View.render (C:\proyectos\google-location-api\node_modules\express\lib\view.js:128:8)
    at tryRender (C:\proyectos\google-location-api\node_modules\express\lib\application.js:640:10)
    at EventEmitter.render (C:\proyectos\google-location-api\node_modules\express\lib\application.js:592:3)
    at ServerResponse.render (C:\proyectos\google-location-api\node_modules\express\lib\response.js:971:7)
    at Request._callback (C:\proyectos\google-location-api\app.js:20:11)

Any ideas?

Ank
  • 1,864
  • 4
  • 31
  • 51
Alejandro
  • 45
  • 1
  • 1
  • 8

2 Answers2

5

I'm guessing it's because you have <% and %> on each line and would recommend making it cleaner so that it parses it properly

<%
    var map;

    function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
            center: {
                lat: -34.397,
                lng: 150.644
            },
            zoom: 8
        });
    };
%>
Brian Putt
  • 1,288
  • 2
  • 15
  • 33
0

Remove spaces before %> tag and after <% tag. Refer https://github.com/mde/ejs/issues/334

<%var map;%>
  <%function initMap(){%>
  <%map = new google.maps.Map(document.getElementById('map'), {%>
  <%center: {lat: -34.397, lng: 150.644},%>
  <%zoom:8%>
  <%});%>
  <%};%>```