【问题标题】:500 SyntaxError: Unexpected token (41:5) while using simple jade file500 SyntaxError: Unexpected token (41:5) while using simple jam file
【发布时间】:2017-01-20 08:43:19
【问题描述】:

我正在学习 Express 和使用 jam 的模板。我编写了非常简单的代码,但我遇到了错误。请告诉我有什么问题。

错误:

500 SyntaxError: Unexpected token (41:5)

at Parser.pp$4.raise (H:\NodeJS-Lynda\Chap-5\06\start\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:2422:15)
at Parser.pp.unexpected (H:\NodeJS-Lynda\Chap-5\06\start\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:613:10)
at Parser.pp.semicolon (H:\NodeJS-Lynda\Chap-5\06\start\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:590:61)
at Parser.pp$1.parseExpressionStatement (H:\NodeJS-Lynda\Chap-5\06\start\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:1002:10)
at Parser.pp$1.parseStatement (H:\NodeJS-Lynda\Chap-5\06\start\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:767:22)
at Parser.pp$1.parseTopLevel (H:\NodeJS-Lynda\Chap-5\06\start\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:655:25)
at Parser.parse (H:\NodeJS-Lynda\Chap-5\06\start\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:525:17)
at Object.parse (H:\NodeJS-Lynda\Chap-5\06\start\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:3300:39)
at reallyParse (H:\NodeJS-Lynda\Chap-5\06\start\node_modules\jade\node_modules\with\node_modules\acorn-globals\index.js:22:16)
at findGlobals (H:\NodeJS-Lynda\Chap-5\06\start\node_modules\jade\node_modules\with\node_modules\acorn-globals\index.js:35:11)

layout.jade:

doctype html
html
    head
        title= title
        link(rel="stylesheet", href="bootstrap.min.css")
    body
        div.container
            block content

list.jade:

我尝试使用以下代码块,但在这两种情况下都出现此错误:


  1. 试用:

extends layout

block content
    h1= title
    ul
        each flight, index in flights
            - flight = flight.getInformation()
            li= flight.number + ': ' + flight.origin + '-' + flight.destination

  1. 试用:

extends layout

block content
    h1= title
    ul
    -   each flight in flights
        -   flight= flight.getInformation()
        li= flight.number   +   ':' +   flight.origin   +   '-' +   flight.destination

getInformation() 是我在另一个模块flight 中编写的方法。 flight 的参数是从调用 list.jade 的 js 文件传递​​的。

请任何人帮我解决这个问题。似乎有一些语法错误,但我不明白吗?谢谢。

【问题讨论】:

    标签: javascript node.js express pug


    【解决方案1】:

    有点晚了,但我刚刚通过深入研究 node_modules 找到了解决方案。对你来说,我会从文件@NodeJS-Lynda\Chap-5\06\start\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js开始

    Parser.pp$1.parseExpressionStatement
    

    转到第 1002 行并注销该行的变量,如果它们没有任何意义,请继续向下移动到堆栈跟踪中的下一行,朝向

    Parser.pp$1.parseTopLevel line 655
    

    重复每个日志,直到它为您提供更清晰的工作。哈巴狗模板将解析所有可能的内容,直到它“中断”,这将为您提供一个非常准确的位置来查看您的确切问题。 IE 就在最后一个日志之外

    【讨论】:

      【解决方案2】:

      将您的body 移动到一个标签中。

      doctype html
      html
          head
              title= title
              link(rel="stylesheet", href="bootstrap.min.css")
              body
                  div.container
                      block content
      

      【讨论】:

      • 感谢您的回复。我正在使用 sublime 编辑器。尝试了您的解决方案,但仍然遇到同样的错误。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多