【问题标题】:SyntaxError: Unexpected token ; while compiling ejsSyntaxError: Unexpected token ;在编译 ejs 时
【发布时间】:2017-06-29 02:09:10
【问题描述】:

我试图在我的 Express 应用程序中使用这个谷歌地图代码,但它给了我一个 syntaxError。我已经过滤了这个函数的错误:

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

错误信息并没有太大帮助:

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)

有什么想法吗?

【问题讨论】:

    标签: node.js express ejs


    【解决方案1】:

    我猜这是因为你在每一行都有&lt;%%&gt;,建议让它更干净,以便正确解析它

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

    【讨论】:

      【解决方案2】:

      删除 %> 标记之前和 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%>
        <%});%>
        <%};%>```
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-10
        • 2020-03-21
        • 1970-01-01
        • 2019-08-14
        相关资源
        最近更新 更多